Javascript:添加onclick属性DOM
我尝试向现有的div元素添加一些侦听器Javascript:添加onclick属性DOM,javascript,jquery,onclick,Javascript,Jquery,Onclick,我尝试向现有的div元素添加一些侦听器 //Prepare div $(this.div).css("z-index","256"); $(this.div).attr("onmouseover",this.myname+".resize();"); $(this.div).attr("onmousedown",this.myname+".resize();"); $(this.div).attr("onmouseo
//Prepare div
$(this.div).css("z-index","256");
$(this.div).attr("onmouseover",this.myname+".resize();");
$(this.div).attr("onmousedown",this.myname+".resize();");
$(this.div).attr("onmouseout","if("+this.myname+".sized)"+ this.myname+".resize();");
但在IE和Chrome中,当事件仍然存在时,它不会被炒鱿鱼
添加到元素属性中。
Firefox按预期工作
有人知道有什么问题吗
谢谢不要将事件设置为字符串。
相反,您应该使用jQuery的
bind
方法:
var me = this; //Inside the handlers, this is the element.
$(this.div).bind('mouseenter mousedown mouseleave', function() {
me.resize();
});
不要将事件设置为字符串。
相反,您应该使用jQuery的
bind
方法:
var me = this; //Inside the handlers, this is the element.
$(this.div).bind('mouseenter mousedown mouseleave', function() {
me.resize();
});
您应该真正使用jquery自己的evenhandling(
.hover()
)而不是添加到属性中。您应该真正使用jquery自己的evenhandling(.hover()
)而不是添加到属性中。@Mereep-您也不必创建4个jquery实例来执行此操作。使用方法链接。@Mereep-也不必创建4个jQuery实例就可以做到这一点。使用方法链接。