<div id= "myDIV"> chickMe</div>
<script type="text/javascript">
obj=document.getElementById("myDIV");
obj.onclick = show;
function show()
{
alert( "dd ");
}
</script>
<script type="text/javascript">
obj=document.getElementById("myDIV");
obj.onclick = show;
function show()
{
alert( "dd ");
}
</script>
<script type= "text/javascript">
obj=document.getElementById("myDIV");
obj.onclick=show;
function show()
{
alert( "dd ");
}
</script>
我要求是兼容ie和firefox
其中还是鼠标单击事件
至少
IE6.0和Firefox/2.0.0.7是可以执行的
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head><body>
<div id="bb" class="bd" style="cursor:pointer">click me
</div>
<script type="text/javascript">
<!--
function addEvent(el,eventType,fn){
if(el.addEventListener){
el.addEventListener(eventType,fn,false);
}else if(el.attachEvent){
el.attachEvent("on" + eventType,fn);
}else{
el["on"+eventType]=fn;
}
} var b = document.getElementById('bb')
addEvent(b,'click',funname)function funname(){
alert(1)
}
//-->
</script>
</body>
</html>
是我测试的条件不同,所以有不同的结果<div id= "myDIV"> chickMe</div>
<script type="text/javascript">
obj=document.getElementById("myDIV");
i=10;
obj.onclick = show(i);
function show(i)
{
alert(i);
}
</script> 这样为什么不行??
i 从哪里来啊。这样写没法给事件传参数啊。
<div id= "myDIV"> chickMe</div>
<script type="text/javascript">
obj=document.getElementById("myDIV");
i=10;
obj.onclick =function(){ show(i)};
function show(i)
{
alert(i);
}
</script>