setAttribute('onclick',function (){})中的传值问题
IE中不支持给事件赋值的,但是FF支持
我写成setAttribute('onclick',“testvalue()”)没有任务反应
写成setAttribute('onclick',testvalue())会直接执行testvalue()函数,但是并不会给对象添加onclick事件
最后我写成setAttribute('onclick',function (){testvalue()})这样终于正确的添加onclick事件了,但是却遇到了一个传值的问题,我的代码如下:
items2 = oDoc.selectNodes("//CLASSNAME/Table/pcl2_id"); var itemsLength=items1.length; for(i=0;i<itemsLength;i++) { var newOption = document.createElement("li"); newOption.setAttribute('onclick',function (){load2(items2[i].text);}) }