IE 8,功能无法链接到输入按钮

罗伯特·塔拉曼兹(Robert Talamantez)

我正在使用“ document.createElement('input')”动态创建按钮输入。该按钮在所有浏览器中均可正常运行,但该功能不会像在所有其他浏览器中一样在IE 8(或IE 7)中触发。我测试了在IE 7和8中被调用的函数的代码,并且该代码可以正常工作。有人知道解决此浏览器问题的方法吗?谢谢你的帮助。

<script type="text/javascript"> 


function killWindow(){

window.open('', '_self', ''); 
window.close(); 

}

document.observe("dom:loaded",function(){
 var forceCloseButton = document.createElement("input");
 forceCloseButton.setAttribute("id","forceClose");
 forceCloseButton.setAttribute("type","image");
 forceCloseButton.setAttribute("src","SurveyResource/Button-Close");
 forceCloseButton.setAttribute("class","button");
 forceCloseButton.setAttribute("onclick","killWindow()");

 var a=$('datstat_bottomcenterbuttons');
a.appendChild(forceCloseButton);
})
</script>
epascarello

您永远都不要使用设置事件处理程序setAttribute

您需要使用addEventListener/attachEventonclick直接设置

同样设置class也会有问题,请看className。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章