动态添加事件失败
var fileuploadNum=1;
var labelNum=1;
function ul1Add()
{
fileuploadNum++;
labelNum++;
var li=document.createElement( "li ");
var fileupload=document.createElement( "input ");
var label=document.createElement( "span ");
fileupload.setAttribute( "type ", "file ");
fileupload.setAttribute( "onmousedown ", "return false; ");
fileupload.setAttribute( "onkeydown ", "return false; ");
fileupload.id= "FileUpload "+fileuploadNum;
li.innerHTML= " <span> 产品快照 "+labelNum+ " </span> ";
li.appendChild(fileupload);
ul1.appendChild(li);
}
<input type= "file " id= "FileUpload1 " onkeydown = "return false; " onmousedown= "return false; "/>
<ul id= "ul1 "> </ul>
在页面上我已经有一个file 控件名为FileUpload1~至于后面的那个事件我是实现用户不能输入或者修改~只能是选择
但是就不知道为什么这段代码所动态生成的file 控件的事件都失效
------解决方案--------------------fileupload.setAttribute( "onmousedown ", "return false; ");
fileupload.setAttribute( "onkeydown ", "return false; ");
up
fileupload.onmousedown = function () { return false; };
fileupload.onkeydown= function () { return false; };
------解决方案--------------------那个onmousedown 和 onkeydown 方法,必须触发一个函数,
所以必须要那样滴。而不是给定 具体值。。
------解决方案--------------------fileupload.setAttribute( "onmousedown ", "return false; ");
fileupload.setAttribute( "onkeydown ", "return false; ");
在IE下是无效的……
在FF下好像有用……