您现在的位置是:首页 > 电脑技术查询 > web开发

请教这样的函数如何绑定?

编辑:chaxungu时间:2022-10-02 23:16:34分类:web开发

请问这样的函数怎么绑定??
document.getElementById("db").onmousedown=function(){
alert(1)
document.getElementById("db").onmousemove=function(){}
document.getElementById("db").onmouseup=function(){}
}我为什么这么问是因为

document.getElementById("aa").innerHTML="<div id='db'></div>";

有这种情况

而绑定是
addEventListner("mousedown",fn,false)

这个fn在这种情况下非常难办了

------解决方案--------------------
老老实实用createElement做就好了
------解决方案--------------------
function init(){
var a="cmls";
document.getElementById("test").attachEvent("onclick",function(){ss(a)});
}
function ss(a){
alert(a);
}
这样试试