鼠标移出一个区域的代码(IE6中测试通过)<div id="aa" onmouseout="test();" style="position:absolute; left:175px; top:81px; width:219px; height:188px; z-index:1; background-color: #999999; layer-background-color: #FFFFFF; border: 1px none #000000;border-color:#000000"> <input id="bb" type....> </input> </div><script> function test(){ var x=event.clientX/1; var y=event.clientY/1; var tleft=document.all.aa.style.left.substr(0,document.all.aa.style.left.length-2)/1 var ttop=document.all.aa.style.top.substr(0,document.all.aa.style.top.length-2)/1 var tright=document.all.aa.style.left.substr(0,document.all.aa.style.left.length-2)/1+document.all.aa.style.width.substr(0,document.all.aa.style.width.length-2)/1 var tbottom=document.all.aa.style.top.substr(0,document.all.aa.style.top.length-2)/1+document.all.aa.style.height.substr(0,document.all.aa.style.height.length-2)/1 if((tleft>=x&&tright>=x)||(tleft<=x&&tright<=x)||(ttop>=y&&tbottom>=y)||(ttop<=y&&tbottom<=y))alert("out"); } </script>
把代码改一改,省得那么吓人: <div id="aa" onmouseout="test(this.style);" style="position:absolute; left:175px; top:81px; width:219px; height:188px;background-color: #999999;"> <br> <input id="bb" type....> </div><script> function test(tag){ var x=event.clientX/1; var y=event.clientY/1; var tleft=tag.left.substr(0,tag.left.length-2)/1 var ttop=tag.top.substr(0,tag.top.length-2)/1 var tright=tag.left.substr(0,tag.left.length-2)/1+tag.width.substr(0,tag.width.length-2)/1 var tbottom=tag.top.substr(0,tag.top.length-2)/1+tag.height.substr(0,tag.height.length-2)/1 if((tleft>=x&&tright>=x)||(tleft<=x&&tright<=x)||(ttop>=y&&tbottom>=y)||(ttop<=y&&tbottom<=y))alert("out"); } </script>
<input id="bb" type....>
</input>
</div><script>
function test(){
var x=event.clientX/1;
var y=event.clientY/1;
var tleft=document.all.aa.style.left.substr(0,document.all.aa.style.left.length-2)/1
var ttop=document.all.aa.style.top.substr(0,document.all.aa.style.top.length-2)/1
var tright=document.all.aa.style.left.substr(0,document.all.aa.style.left.length-2)/1+document.all.aa.style.width.substr(0,document.all.aa.style.width.length-2)/1
var tbottom=document.all.aa.style.top.substr(0,document.all.aa.style.top.length-2)/1+document.all.aa.style.height.substr(0,document.all.aa.style.height.length-2)/1
if((tleft>=x&&tright>=x)||(tleft<=x&&tright<=x)||(ttop>=y&&tbottom>=y)||(ttop<=y&&tbottom<=y))alert("out");
}
</script>
把代码改一改,省得那么吓人:
<div id="aa" onmouseout="test(this.style);" style="position:absolute; left:175px; top:81px; width:219px; height:188px;background-color: #999999;">
<br>
<input id="bb" type....>
</div><script>
function test(tag){
var x=event.clientX/1;
var y=event.clientY/1;
var tleft=tag.left.substr(0,tag.left.length-2)/1
var ttop=tag.top.substr(0,tag.top.length-2)/1
var tright=tag.left.substr(0,tag.left.length-2)/1+tag.width.substr(0,tag.width.length-2)/1
var tbottom=tag.top.substr(0,tag.top.length-2)/1+tag.height.substr(0,tag.height.length-2)/1
if((tleft>=x&&tright>=x)||(tleft<=x&&tright<=x)||(ttop>=y&&tbottom>=y)||(ttop<=y&&tbottom<=y))alert("out");
}
</script>
paseInt(document.all.aa.style.left)
////////////////////////
二楼的不好使
paseInt(document.all.aa.style.left)////////////////////////
两个问题:1、怎么个“不好使”法?2、为什么一定要用:paseInt()?
在div和div上的控件交叉时产生 onmouseout事件,这时id="aa",所以还是会出现的paserInt(100px)=100 简单一些吧
按照你的说法,代码上的确简单了点。另外,左边距的数值要多加 1 到 2 才行的,否则向左、向上移出不是很灵敏。
如下:
<div id="aa" onmouseout="test(this.style);" style="position:absolute; left:175px; top:81px; width:219px; height:188px;background-color: #999999;">
<br>
<input id="bb" type....>
</div><script>
function test(tag){
var x=event.clientX;
var y=event.clientY;
var tleft=parseInt(tag.left)+1
var ttop=parseInt(tag.top)+1
var tright=parseInt(tag.left)+parseInt(tag.width)
var tbottom=parseInt(tag.top)+parseInt(tag.height)
if((tleft>=x&&tright>=x)||(tleft<=x&&tright<=x)||(ttop>=y&&tbottom>=y)||(ttop<=y&&tbottom<=y))alert("out");
}
</script>