如何调用td的id来改变css样式onclick
问题描述:
看下面是我的代码来改变使用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。
答
试试这个
window.onload = function() {
document.getElementById('auth').onclick=change;
};
function change(){
this.className="authorised_reporter";
document.getElementById('main').className="authorised_reporter";
}
答
你的问题不是很清楚。从你所说的,这听起来像这是你想做的事,但我怀疑这可能并非如此...:
function change() {
this.className = "authorised_reporter";
document.getElementById('main').className = "authorised_reporter";
}
,它为我工作,感谢您的帮助 – user2086641 2013-04-25 19:56:18
你是欢迎。 – Anoop 2013-04-25 19:56:56
你应该接受这个答案,因为它为你工作。 – sgroves 2013-04-25 20:09:06