<html>
<title>这是一段测试代码</title>
<script type="text/javascript">function test(obj){
if (document.all){ //IE
obj.innerHTML+="<br/>obj:"+obj.getAttribute("id")+"<br/>obj\.firstChild:"+obj.firstChild.getAttribute("id")+"<br/>event.toElement:"+event.toElement.getAttribute("id");
obj.innerHTML+="<br/>obj.contains(obj.firstChild):"+obj.contains(obj.firstChild)+"<br/>obj.contains(event.toElement):"+obj.contains(event.toElement)+"<br/>";
}}
</script>
<body>
<div id="outer" style="width:400px;height:300px;background:#ccc;" onmouseover="test(this);"><div id="inner" style="width:300px;height:200px;background:#333;"></div></div>
</body></html>
测试环境:IE9
问题一:当鼠标移动到$("inner")上时,obj.contains(obj.firstChild)与obj.contains(event.toElement)执行结果为何不同?(此时通过元素id可知“obj.firstChild”与“event.toElement”为同一节点,obj是不变的)
问题二:当鼠标移动到$("inner")上时,test函数怎么执行了不止一次?
问题三:在<html>前加上<!DOCTYPE HTML>后调试结果为:对象不支持getAttribute属性或方法;
<title>这是一段测试代码</title>
<script type="text/javascript">function test(obj){
if (document.all){ //IE
obj.innerHTML+="<br/>obj:"+obj.getAttribute("id")+"<br/>obj\.firstChild:"+obj.firstChild.getAttribute("id")+"<br/>event.toElement:"+event.toElement.getAttribute("id");
obj.innerHTML+="<br/>obj.contains(obj.firstChild):"+obj.contains(obj.firstChild)+"<br/>obj.contains(event.toElement):"+obj.contains(event.toElement)+"<br/>";
}}
</script>
<body>
<div id="outer" style="width:400px;height:300px;background:#ccc;" onmouseover="test(this);"><div id="inner" style="width:300px;height:200px;background:#333;"></div></div>
</body></html>
测试环境:IE9
问题一:当鼠标移动到$("inner")上时,obj.contains(obj.firstChild)与obj.contains(event.toElement)执行结果为何不同?(此时通过元素id可知“obj.firstChild”与“event.toElement”为同一节点,obj是不变的)
问题二:当鼠标移动到$("inner")上时,test函数怎么执行了不止一次?
问题三:在<html>前加上<!DOCTYPE HTML>后调试结果为:对象不支持getAttribute属性或方法;
解决方案 »
- 正则匹配包含属性的html标签的内容??
- js如何获取被嵌套页IE地址栏地址?
- document.getElementsByName("selectFlag").length怎么取值
- 让下拉框里值等于VAR1的一项选中???
- 请教高手 光标定位的问题
- 什么叫正则表达式?
- 如何在客户端进行分页显示记录?
- 在form中显示一个红色方块,当点击Button后使红色方块扩大一倍,这怎么实现??
- 如何判断网页的代码中的ID号的存在??
- 移动端图片左右移动有没有高手给一个精简的代码
- Jquery 动态改变bacakground-img 的问题,url() 里面的用变量不行
- 文章搜索加验证码并验证验证码的代码哪里出错了?请指点。
function onmouseover(event) {
test(this);
}
中event在调试下为mouseover clientX=399, clientY=209
也就是只要坐标一改变event就被触发一次,也就是为什么在IE9环境下,在黑色框中只要鼠标移动就会多数据了