我想知道如何按 Enter,但当目标元素上存在特定类时不按?
jQuery("#input").keypress(function (e) {
if (e.keyCode == 13 && jQuery('.classTest').not(this)) {
//any item selected with enter EXCEPT which has .classTest
}
});
?
最佳答案
附注使用.input
! ID 仅适用于一个元素。
WORKING DEMO
jQuery(".input").keypress(function (e) {
if (e.keyCode == 13 && !(jQuery(this).hasClass('classTest')) ) {
alert('enter!');
}
});
使用的代码:
!( $(this).hasClass('classTest') )
! = 不
jQuery API .hasClass()
关于jQuery 按 Enter 不在类里面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7462369/