我在一个div里面同时添加了onmouseover,onmouseout事件。但onmouseout事件不会触发。代码如下
function doOver(){
document.body.innerHTML = document.body.innerHTML+"1 "
}
function doOut(){
document.body.innerHTML = document.body.innerHTML+"2 "
}
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseout="doOut()">111</div></div>
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseover="doOver()" onmouseout="doOut()">111</div></div>鼠标从第一个div移出时,会执行doOut()方法,但鼠标从第2个div移出时,不会执行doOut()方法。鼠标在第2个div内移动,会调用doOver()方法。
请问:我如何让鼠标从第2个div移出时,也要执行doOut()方法???????????
function doOver(){
document.body.innerHTML = document.body.innerHTML+"1 "
}
function doOut(){
document.body.innerHTML = document.body.innerHTML+"2 "
}
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseout="doOut()">111</div></div>
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseover="doOver()" onmouseout="doOut()">111</div></div>鼠标从第一个div移出时,会执行doOut()方法,但鼠标从第2个div移出时,不会执行doOut()方法。鼠标在第2个div内移动,会调用doOver()方法。
请问:我如何让鼠标从第2个div移出时,也要执行doOut()方法???????????
<script type="text/javascript">
function doOver() { alert('over'); }
function doOut() { alert('out'); }
</script>
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseout="doOut()">111</div></div>
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseover="doOver()" onmouseout="doOut()">111</div></div>
function doOver() { document.getElementById("xs").value="over"; }
function doOut() { document.getElementById("xs").value="out";}
</script>
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseout="doOut()">111</div></div>
<div style="height:40px;"><div style="width:100px;height:30px;border:1px solid black;" onmouseover="doOver()" onmouseout="doOut()">111</div></div>
<input type="text" name="xs" id="xs"/>
改成下面的
function doOver() { alert('over'); }
function doOut() { alert('out'); }或者是:
在两个div上面加多一个
<div id="mousetest"></div>
然后js代码修改为
function doOver(){
document.getElementById("mousetest").innerHTML += "1 "
}
function doOut(){
document.getElementById("mousetest").innerHTML += "2 "
}测试的时候,尽量不要用"document.body"当成“画板”