运行一个特定的<script>(Dreamweaver)

时间:2016-05-08 06:54:19

标签: javascript html dreamweaver

我正在使用Dreamweaver(CC 2015)为学校创建一个网站,我在标签中使用JavaScript来更改文本的颜色,当您单击另一个文本主体时。我想要它所以只有一个特定的脚本运行才能只改变一个文本体,但是,当它顺序运行时,它只会改变最后一个,无论我点击哪一个。我正在使用的代码如下所示。

&#xA;&#xA;
 &lt; script&gt;&#xA; function changeColor(NES)&#xA;&#xA; { document.getElementById('NES')。style.color =“rgba(229,6,10,1.00)”; &#xA;&#xA;&lt; / script&gt;&#xA;&#xA;&lt; script&gt;&#xA; function changeColor(SES)&#xA;&#xA; {document.getElementById('SES ')。style.color =“rgba(229,6,10,1.00)”;}&#xA;&#xA;&lt; / script&gt;&#xA;&#xA;&lt; script&gt;&#xA; function changeColor(GB)&#xA;&#xA; {document.getElementById('GB')。style.color =“rgba(229,6,10,1.00)”;}&#xA;&#xA;&lt; ; / script&gt;&#xA;  
&#xA;&#xA;

以及

&#xA;&#xA;
 &lt ; a href =“#”onclick =“changeColor(NES); return false;”&gt; NES&lt; / a&gt;&#xA;&#xA;&lt; a href =“#”onclick =“changeColor(SES);返回false;“&gt;超级NES&lt; / a&gt;&#xA;&#xA;&lt; a href =”#“onclick =”changeColor(GB); return false;“&gt; Game Boy&lt; / a&gt;& #xA;  
&#XA;

1 个答案:

答案 0 :(得分:0)

<script>
function changeColor(div)
{
    div.style.color = "rgba(229,6,10,1.00)"; 
}
</script>

<a href="#" onclick="changeColor(this);">NES</a>

<a href="#" onclick="changeColor(this);">Super NES </a>

<a href="#" onclick="changeColor(this);">Game Boy</a>