1

我正在编写一个每页有 200 多个链接的网页。每个链接都有一个与另一个帧中的 id 匹配的唯一 id。我想运行一个 onmouseover 函数,该函数将跨帧更改两个链接的文本颜色。这是我到目前为止所得到的。

<html><head><title>Test</title>
  <script>
    function hey()
      {var id=//HELP PLEASE; document.getElementById(id).style.color = "red";} 
    function bye()
      {var id=//HELP PLEASE; document.getElementById(id).style.color = "black";}
  </script>
 </head>
<body>
 <a id="1" class="word" onmouseover="hey()" onmouseout="bye()">hello</a> 
 <a id="2" class="word" onmouseover="hey()" onmouseout="bye()">world</a>....
</body></html>

有什么想法吗?

4

1 回答 1

2

将 id 传递给函数:

<html><head><title>Test</title>
  <script>
    function hey(id)
      {document.getElementById(id).style.color = "red";} 
    function bye(id)
      {document.getElementById(id).style.color = "black";}
  </script>
 </head>
<body>
 <a id="1" class="word" onmouseover="hey(this.id)" onmouseout="bye(this.id)">hello</a> 
 <a id="2" class="word" onmouseover="hey(this.id)" onmouseout="bye(this.id)">world</a>....
</body></html>
于 2013-02-19T21:52:33.257 回答