首页 新闻 会员 周边

给页面添加回车事件

0
悬赏园豆:5 [待解决问题]

如何给页面中添加回车事件,有些控件是动态添加的。

KISS&Nikita的主页 KISS&Nikita | 初学一级 | 园豆:188
提问于:2015-01-19 09:06
< >
分享
所有回答(5)
0

动态绑定键盘按下事件就可以啊.

晓菜鸟 | 园豆:2594 (老鸟四级) | 2015-01-19 09:35
0

添加控件后在绑定事件就好

刘宏玺 | 园豆:14020 (专家六级) | 2015-01-19 09:55
0
 1     
 2 <hml>
 3 
 4 <head>
 5     
 6     <title></title>
 7     
 8     <script id="jquery_183" type="text/javascript" class="library" src="/js/sandbox/jquery/jquery-1.8.3.min.js"></script>
 9 </head>
10 
11 
12 <body>
13     
14     <div id="divContainer">
15     
16     </div>
17     
18 </body>
19 </hml>
 1 // for http://q.cnblogs.com/q/69274/
 2 ;(function(doc,$){
 3 
 4     var m={};
 5     
 6     m.view={
 7         
 8         initialize:function(){
 9             this.createElement();
10         },
11         
12         createElement:function(){
13             var txtKeyword=doc.createElement('INPUT'),
14                     divContainer=doc.getElementById('divContainer');
15             txtKeyword.setAttribute('id','txtKeyword');
16             txtKeyword.setAttribute('type','text');
17             divContainer.appendChild(txtKeyword);
18         }
19     };
20     
21     m.event={
22         
23         initialize:function(){
24             
25             this.bindEnterClickHandle();
26         },
27         
28         bindEnterClickHandle:function(){
29             var handler=function(evt){
30                 var keyCode=evt.keyCode;
31                 switch(keyCode){
32                     case 13:
33                         console.log('enter');
34                         break;
35                     default:break;
36                 }
37             };
38             
39             $(doc).delegate('input[type=text]','keyup',handler);
40             
41         }
42     };
43     
44     m.initialize=function(){
45         m.view.initialize();
46         m.event.initialize();
47     };
48     
49     $(doc).ready(function(){
50         m.initialize();
51     });
52     
53     
54 })(document,jQuery);

demo here

Vivian软陶公仔 | 园豆:284 (菜鸟二级) | 2015-01-19 10:08
0

监听document的keyup事件

水晶途途 | 园豆:1443 (小虾三级) | 2015-01-19 10:37
0

jquery操作

沐心 | 园豆:204 (菜鸟二级) | 2015-01-19 16:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册