2013-04-25 63 views
0

看下面是我的代碼來改變使用javascript的td onclick的背景。如何調用td的id來改變css樣式onclick

window.onload = function() { 
    document.getElementById('auth').onclick=change; 
}; 
function change(){ 
    this.className="authorised_reporter"; 
} 

如何改變另一TD的CSS同時在點擊一個td.see我的HTML

<td id="main" class="account_holder"> 
<h1 align="center">Main Account Holder</h1></td> 

<td id="auth" class="authorised_reportericon" >    
    <p align="center" style="color:black;font-size:16px;">Authorised Reporters</p></a> 
</td> 

什麼,我希望是onclicking授權記者的TD,TD這主要與賬戶持有人TD的背景下也得到改變。這是可能的JavaScript。

回答

0

試試這個

window.onload = function() { 
document.getElementById('auth').onclick=change; 
}; 
function change(){ 
    this.className="authorised_reporter"; 
    document.getElementById('main').className="authorised_reporter"; 

} 
+0

,它爲我工作,感謝您的幫助 – user2086641 2013-04-25 19:56:18

+0

你是歡迎。 – Anoop 2013-04-25 19:56:56

+0

你應該接受這個答案,因爲它爲你工作。 – sgroves 2013-04-25 20:09:06

0

你的問題不是很清楚。從你所說的,這聽起來像這是你想做的事,但我懷疑這可能並非如此...:

function change() { 
    this.className = "authorised_reporter"; 
    document.getElementById('main').className = "authorised_reporter"; 
}