jQuery检查元素上是否存在onClick [英] jQuery check if onClick exists on element
本文介绍了jQuery检查元素上是否存在onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找到了检查元素上是否存在事件的方法。但它不适用于未被jQuery委派的事件......
I found the way to check if event exists on element. But it's not work on the events which is not delegated by jQuery...
当我尝试时,
$("a").data("events");
为此。
<a href="#" onClick="alert('Hello, World!')" />
返回未定义。
是否有有没有办法检查jQuery上的元素是否存在 onClick ?
Is there any way to check if onClick exists on elements with jQuery?
谢谢。
推荐答案
你可以这样做:
if ($('a').attr("onClick") != undefined) {}
这篇关于jQuery检查元素上是否存在onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文