2011-02-17 47 views
0

我需要更改点击超链接文本的颜色时,它是一个div的一部分。有在同一div许多超链接,如下图所示:<%= link_to_remote>,更改超链接文本颜色Onmouseclick

<div id="link"<br> 
    <b>Period:</b> 
    (<%= link_to_remote "Today", :url =>{:action =>'period_list',:period=>"today"},:onmouseclick=>"changeColor(this,'#FF0000');"%>/ 
    <%= link_to_remote "This week", :url =>{:action =>'period_list',:period=>"weeks"}%>/ 
    <%= link_to_remote "This month", :url =>{:action =>'period_list',:period=>"months"}%> 
    </div> 

<head>下面的代码给出:

<script type="text/javascript" language="javascript"> 
function changeColor(idObj,colorObj) 
{ 
    document.getElementById(idObj.id).style.color = colorObj; 
} 
</script> 

但是,“今天”点击后,文本颜色不会改变。

您能否给出一个解决方案来解决这个问题。

感谢...

回答

0

你不给链接给ID,所以idObj.id返回空字符串和document.getElementById(idObj.id)返回null。

为了解决这个问题,而不是有这样的代码:

idObj.style.color = colorObj;