Ran into this problem today, posting in case someone else has the same issue.
var execBtn = document.createElement('input'); execBtn.setAttribute("type", "button"); execBtn.setAttribute("id", "execBtn"); execBtn.setAttribute("value", "Execute"); execBtn.setAttribute("onclick", "runCommand();");
Turns out to get IE to run an onclick on a dynamically generated element, we can't use setAttribute. Instead, we need to set the onclick property on the object with an anonymous function wrapping the code we want to run.
execBtn.onclick = function() { runCommand() };
BAD IDEAS:
You can do
execBtn.setAttribute("onclick", function() { runCommand() });
相关推荐
博客园闪存分页是用JavaScript生成的,今天发现在IE8下点击页码不能翻页,翻页操作是在当前页码的...由于IE8不支持setAttribute方法,这里添加的onclick事件处理程序并未添加上。 后来改为jQuery的attr方法: 代码如
代码如下: var asubmit = document.... //在火狐中有效,而在ie中无效 代码如下: <span xss=removed> asubmit.setAttribute(“onclick”,”[removed]document.buyform.submit();”);</span> //在ie中有效,火
测试环境(客户端浏览器 ) IE6,IE7, IE8兼容模式, IE8 Firefox 3.6.8, google chrome 5.0.375.125 先来说明两个函数的标准定义。 elementNode.setAttribute(name,... 一、setAttribute的问题 elementNode为<tr>
这里利用 setAttribute 指定 onclick 属性,简单,很好理解, 但是:IE 不支持,IE 并不是不支持 setAttribute 这个函数,而是不支持用 setAttribute 设置某些属性,包括对象属性、集合属性、事件属性,也就是说用 ...
有些时候需要动态加载javascript事件的一些方法往往我们需要在 JS 中动态添加事件,这就涉及到浏览器兼容性问题了...但是:IE 不支持,IE 并不是不支持 setAttribute 这个函数,而是不支持用 setAttribute 设置某些属性
在IE中脚本不能以setAttribute()来设置其样式信息(css),必须采用element.style.property=value(注:此处value为要设定的值)的方式来实现某个元素的呈现效果。 eg.document.getElementById(“id”).style....
IE不是很乖,在IE里setAttribute只认一些静态属性,而像ONCLICK事件时无效的,要用attchEvent方法 无标题文档 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
pops[degree].document.body.setAttribute("degree", degree); return pops[degree]; } CreatePopup(1); //创建一个2层的Popup家族 这个方法可以解决多个Popup共存的问题,只是如果要使用这个方法来实现...
但是IE不支持用 setAttribute 设置某些属性,包括对象属性、集合属性、事件属性,也就是说用 setAttribute 设置 style、onclick、onmouseover 这些属性在 IE 中是行不通的。 方法二、用 attachEvent 和 ...
<!...--STATUS OK--><html><head>;charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><link rel="dns-prefetch" href="//s1.bdstatic.com"/><link rel="dns-prefetch" href="//t1.baidu....