<head>
<style>
#floater {
position: absolute;
left: 500;
top: 146;
width: 125;
visibility: visible;
z-index: 10
}
</style>
</head>
<body id="body1">
<div ID="floater" style="left: 500px; top: 158px">
<p id="p1" align="center"> <img id="img1" SRC="1.gif" alt="图片显示的文字" WIDTH="125" HEIGHT="60"> <br>
<font color="#FF8040">2008北京欢迎你 </font> </p>
</div>
<script>
if(document.all)
{
document.onmousedown = grabIt;
}
function grabIt(e)
{
if(document.all)
{
whichIt = event.srcElement;
alert(whichIt.id);
alert(whichIt.parentElement.id);
}
}
</script>
</body>
细看
解决方案 »
- js中的 if (val[1]===this.undefined) 和 if (val[1]== "yes") 中的 三个等于 和 两个等于有什么区别?
- 怎样使flash变成灰色
- 求教關於Ext擴展控件問題
- overflow FF 兼容问题
- 如何实现点击删除按钮可以删除掉统计数据中该条数据的值,如何调用JS,在线等,麻烦大家了啊!!!
- 上下滑动菜单,求思路
- 小问题,获得焦点
- 很多论坛都解决不了的问题
- 与后台交互的等待时间的动画如何实现
- python+selenium始终获取不到页面的alert弹窗一直报错,求大神帮忙啊
- 鱼与熊掌亦能兼得!学知识又拿分:“百度空间统计图表经典JS”高手请进!
- 求一段背景颜色交替的JS代码
就要下面两个输出来看看:理论上下面两个是不等的,但是事实是相等的。
就问这个为什么???????
alert(whichIt)
alert(whichIt.parentElement)
我这里显示一个[object]一个null
<html>
<head>
<style>
#floater {
position: absolute;
left: 500;
top: 146;
width: 125;
visibility: visible;
z-index: 10
}
</style>
</head>
<body>
<div ID="floater" style="left: 500px; top: 158px">
<p align="center"> <img SRC="1.gif" alt="图片显示的文字" WIDTH="125" HEIGHT="60"> <br>
<font color="#FF8040">2008北京欢迎你 </font> </p>
</div>
<script>
if(document.all)
{
document.onmousedown = grabIt;
}
function grabIt(e)
{
if(document.all)
{
whichIt = event.srcElement;
alert(whichIt)
alert(whichIt.parentElement)
}
}
</script>
</body>
</html>
whichIt.parentElement是发生事件元素的父元素,怎能相等?
看id
看我的名字,服特,呵呵
object是对象啊,都叫你运行我的例子了,不信
这个发生事件的元素是document吗?
whichIt.parentElement是发生事件元素的父元素
那这个父元素是谁,是window吗,为什么点击图片和其他地方结果不一样。
event.srcElement是不同的<img>标签有父元素
而document没有。
<head>
<style>
#floater {
position: absolute;
left: 500;
top: 146;
width: 125;
visibility: visible;
z-index: 10
}
</style>
</head>
<body>
<div ID="floater" style="left: 500px; top: 158px;border:1px solid red;">
<p align="center">
<img SRC="http://www.baidu.com/img/baidu_logo.gif" alt="图片显示的文字" WIDTH="125" HEIGHT="60"><br/>
<font color="#FF8040">2008北京欢迎你 </font>
</p>
</div>
<font color="#FF8040">2008北京欢迎你 </font>
<script>
if(document.all)
{
document.onmousedown = grabIt;
}
function grabIt(e)
{
if(document.all)
{
whichIt = event.srcElement;
alert(whichIt.innerHTML)
alert(whichIt.parentElement.innerHTML)
}
}
</script>
</body>
{
whichIt = event.srcElement;
alert(whichIt.tagName);
alert(whichIt.parentElement);
}
这个试试,呵呵。