[英]jQuery disable click but not link
I just want to disable the ability for a user to click, with the exception of links 我只想禁用用户点击的功能(链接除外)
$('selector').children().not('a').click(function(e) {
return false;
});
this doesn't work.. thanks 这行不通..谢谢
children
only selects the immediate children. children
只会选择直子。
To disable all of selector
's descendants, use this: 要禁用
selector
的所有后代,请使用以下命令:
$('selector :not(a)').click(function(e) {
e.preventDefault()
});
Or, to be a little more efficient, use delegation: 或者,为了更有效一点,请使用委托:
$('selector').on('click', ':not(a)', function(e) {
e.preventDefault()
});
When you want to disable the user from clicking stuff other than links, simply do this: 如果要禁止用户单击链接以外的内容,只需执行以下操作:
$('selector').find(':not(a)').click(function(e){
e.preventDefault()
})
It applies to all elements other than links. 它适用于链接以外的所有元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.