whichlink = (e.target) ? e.target.id : e.srcElement.id;
是不是whichlink这个变量存储了一个信息,即是否定义了e.target,若定义了e.target则等于e.target.id 若没定义即为e.srcElement.id?这两个哪个能在IE中运行,哪个能在火狐中运行?
是不是whichlink这个变量存储了一个信息,即是否定义了e.target,若定义了e.target则等于e.target.id 若没定义即为e.srcElement.id?这两个哪个能在IE中运行,哪个能在火狐中运行?
srcElement是IE私有的属性,target是W3C标准属性,都是引用了触发事件的元素。
obj=document.getElementById(whichlink+"menu");
这里的menu是什么意思?
HTML代码如下<html>
<head><title>Creating a Navigation Tree</title>
<style>
A {text-decoration: none;}
#productsmenu,#supportmenu,#contactmenu {
display: none;
margin-left: 2em;
}
</style>
</head>
<body>
<h1>Navigation Tree Example</h1>
<p>The navigation tree below allows you to expand and
collapse items.</p>
<ul>
<li><a id="products" href="#">[+] Products</a>
<ul ID="productsmenu">
<li><a href="prodlist.html">Product List</a></li>
<li><a href="order.html">Order Form</a></li>
<li><a href="pricelist.html">Price List</a></li>
</ul>
</li>
<li><a id="support" href="#">[+] Support</a>
<ul id="supportmenu">
<li><a href="sforum.html">Support Forum</a></li>
<li><a href="scontact.html">Contact Support</a></li>
</ul>
</li>
<li><a ID="contact" href="#">[+] Contact Us</a>
<ul id="contactmenu">
<li><a href="contact1.html">Service Department</a></li>
<li><a href="contact2.html">Sales Department</a></li>
</ul>
</li>
</ul>
<script language="javascript" type="text/javascript"
src="tree.js">
</script>
</body>
</html>
可能是products,support或者contact
"menu"是常量,
把他们拼接起来
obj就可能是
obj=document.getElementById("productsmenu");或者
obj=document.getElementById("suppormenu");或者
obj=document.getElementById("contactmenu");
? :是三元运算符,
A?B:C,表示当A为真(true)的时候,执行B,为假(false)的时候执行C当e.target未定义或值为空的时候(即为false),whichlink为 e.srcElement.id,否则whichlink为 e.target.id
whichlink 就是为了获得元素的id值 obj=document.getElementById(whichlink+"menu");就是拿到了上边的id 然后与menu拼接成一个字符串 这个字符串可能正好是某个元素的id 这样可以动态操作某个元素的一些东西