开发者

jQuery Press Enter Not on Class

I开发者_如何学运维 was wondering how to press Enter but NOT when a particular class exists on the element being targeted ?

jQuery("#input").keypress(function (e) {
       if (e.keyCode == 13 && jQuery('.classTest').not(this)) {
         //any item selected with enter EXCEPT which has .classTest
       }
   });

?


P.S. use .input! ID's are for ONE element only.

WORKING DEMO

jQuery(".input").keypress(function (e) {
       if (e.keyCode == 13 && !(jQuery(this).hasClass('classTest')) ) {           
               alert('enter!');                   
       }
});

Code used:
!( $(this).hasClass('classTest') )
! = not
jQuery API .hasClass()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜