我想以这种方式添加像mouseenter
jQuery的事件像如何添加在线jQuery的事件
ImageTag mouseenter="callSomefunction" id="imgId"
,而不是
ImageTag onmouseover="callSomefunction" id="imgId"
我怎样才能做到这一点?
我想以这种方式添加像mouseenter
jQuery的事件像如何添加在线jQuery的事件
ImageTag mouseenter="callSomefunction" id="imgId"
,而不是
ImageTag onmouseover="callSomefunction" id="imgId"
我怎样才能做到这一点?
jQuery不作为属性在标签上工作。
你需要找到与JavaScript中的元素,所以在JavaScript块,你会发现该元素,那么你就可以绑定一个事件:
<script>
$("#imgId").mouseenter(function() { /* your stuff */ });
</script>
这个脚本块必须在元素之后执行的,因为在尝试获取它之前,该元素必须存在。
你应该尝试任何事情之前阅读更多关于jQuery的,http://jquery.com/
没有停止你添加whathever你想在你的标记,但是:
要回答你的问题:
<img id="imgId" mouseenter="callSomefunction" />
我不虽然推荐这种方法。
你为什么要这样做?你会给我们一些理由,这种方法吗? – aorcsik 2011-06-06 11:51:17