我有一个页面,当我将鼠标悬停在链接上时,它会在页面的另一部分上更改图像和一些html。但是,我想知道这个脚本是如何工作的,当我看到页面顶部的脚本时:
<script type="text/javascript">
var CONTENT_CURRENT = 0;
showContent = function() {
if (CONTENT_CURRENT > 0) {
var o = YAHOO.util.Dom.get('content' + CONTENT_CURRENT);
o.style.display = 'none';
var a = YAHOO.util.Dom.get('link' + CONTENT_CURRENT);
a.style.color = '#46689e';
}
var c = YAHOO.util.Dom.get('content' + arguments[0]);
c.style.display = 'block';
var l = YAHOO.util.Dom.get('link' + arguments[0]);
l.style.color = '#000000';
CONTENT_CURRENT = arguments[0];
};
YAHOO.util.Event.onDOMReady(function() { showContent('1'); });
</script>
此脚本如何设置页面上的元素?实际页面位于:
标题为“流媒体软件产品”......
答案 0 :(得分:2)
您需要了解另一个代码块才能理解此代码
<div class="real-products-mid-lh">
<a id="link5" href="/products/helix_server.aspx" onmouseover="showContent('5')">Helix Server</a><br />
<a id="link1" href="/products/rlp.aspx" onmouseover="showContent('1')">Real License Program</a><br />
<a id="link2" href="/products/helix_security_manager.aspx" onmouseover="showContent('2')">Helix Security Manager</a><br />
<a id="link3" href="/products/real_player_enterprise_manager.aspx" onmouseover="showContent('3')">RealPlayer Enterprise</a><br />
<a id="link4" href="/products/helix_mobile_server.aspx" onmouseover="showContent('4')">Helix Mobile Server</a><br />
<a id="link6" href="/products/helix_proxy.aspx" onmouseover="showContent('6')">Helix Proxy</a><br />
<a id="link7" href="/products/real_producer.aspx" onmouseover="showContent('7')">RealProducer</a><br />
<a id="link8" href="/products/capture_station.aspx" onmouseover="showContent('8')">Accordent Capture Station</a><br />
<a id="link9" href="/products/elp.aspx" onmouseover="showContent('9')">Real Education Licensing</a><br />
<a id="link10" href="/products/helix_mobile_producer.aspx" onmouseover="showContent('10')">Helix Mobile Producer</a>
</div>
此处列表中的每个链接都以showContent作为参数调用showContent。下面有一堆像这样的div:
<div id="content1" style="display:none;">
<div class="real-products-mid-rh">
<div class="real-products-logos">
<table width="100%" cellpadding="0" cellspacing="0" style="border:1px solid #d6d6d6; height:107px;">
<tr>
<td align="center"><a href="/products/rlp.aspx"><img src="/_common/images/logo_real_sm.gif" alt="Real License Program" style="vertical-align:middle" /></a></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" style="border-left:1px solid #d6d6d6; border-right:1px solid #d6d6d6; border-bottom:1px solid #d6d6d6; padding-top:5px; padding-bottom:5px;">
<tr align="center">
<td><a href="/products/rlp.aspx"><strong>LICENSE PROGRAM</strong></a></td>
<td><a href="/products/rlp.aspx"><img src="/_common/images/px_more.gif" alt="Find out more" /></a></td>
<td> </td>
</tr>
</table>
</div>
<p><strong>Cost effective and all encompassing RealNetworks License Programme available exclusively to UK enterprise customers<br />
<a href="/products/rlp.aspx">Real License Program <img src="/_common/images/px_more.gif" alt="Find out more" /></a></strong></p>
</div>
</div>
该div的ID是“content1”。所以showContent函数做了三件事:
这会导致鼠标悬停时链接右侧的内容发生变化。
答案 1 :(得分:0)
YAHOO.util.Dom.get()
的作用类似于document.getElementById()
o.style.display = 'none'; // hides current content
a.style.color = '#46689e'; // paints current link blue
c.style.display = 'block'; // displays new content
l.style.color = '#000000'; // paints new link black