的setAttribute,的onClick和跨浏览器兼容 [英] setAttribute, onClick and cross browser compatibility

查看:111
本文介绍了的setAttribute,的onClick和跨浏览器兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一些关于这个职位,但没有任何坚实的答案。这是我的code:

I have read a number of posts about this but none with any solid answer. Here is my code:

// button creation
onew = document.createElement('input');
onew.setAttribute("type", "button");
onew.setAttribute("value", "hosts");
onew.onclick = function(){fnDisplay_Computers("'" + alines[i] + "'"); }; // ie
onew.setAttribute("onclick", "fnDisplay_Computers('" + alines[i] + "')"); // mozilla
odiv.appendChild(onew);

现在,在setAttribute()方法(与Mozilla的注释)工作正常,在Mozilla,但只有当它来到它上面的行之后。因此,换句话说,似乎只是默认为取其被最后设置。该.onclick方法(使用IE注释)不能在这两种情况下工作,我使用的是它不正确?

Now, the setAttribute() method (with the mozilla comment) works fine in mozilla but only if it comes AFTER the line above it. So in other words it seems to just default to whichever gets set last. The .onclick method (with the ie comment) does not work in either case, am I using it incorrectly?

无论哪种方式,我不能找到一种方法,使这项工作在所有的IE浏览器,更何况在这两个。我没有使用.onclick方法时改变函数调用它工作得很好用,以这就是为什么我相信我的语法不正确的警报功能只是一个简单的电话。

Either way I can't find a way to make this work at all in IE, let alone in both. I did change the function call when using the .onclick method and it worked fine using just a simple call to an alert function which is why I believe my syntax is incorrect.

长话短说,我不能得到的onclick参数,IE / Mozilla浏览器之间一致地工作。

Long story short, I can't get the onclick parameter to work consistently between IE/Mozilla.

- 尼古拉斯

推荐答案

我通常使用这样​​的:

I usually use something like:

onew.onclick = new Function("fnDisplay_Computers('" + alines[i] + "')");

这应该在IEËFirefox中两者。

this should work both in IE e Firefox.

这篇关于的setAttribute,的onClick和跨浏览器兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆