Javascript 如何呼叫td';s id更改css样式onclick
下面是我使用javascript更改td onclick背景的代码Javascript 如何呼叫td';s id更改css样式onclick,javascript,html,css,Javascript,Html,Css,下面是我使用javascript更改td onclick背景的代码 window.onload = function () { document.getElementById('auth').onclick=change; }; function change(){ this.className="authorised_reporter"; } 如何在单击一个td时同时更改另一个td的css。请参阅我的html <td id="main" class="account_h
window.onload = function () {
document.getElementById('auth').onclick=change;
};
function change(){
this.className="authorised_reporter";
}
如何在单击一个td时同时更改另一个td的css。请参阅我的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>
主要账户持有人
授权记者
我期待的是点击授权记者的td,该td的背景和主要账户持有人td也会发生变化。是否可以使用javascript进行更改。试试这个
window.onload = function () {
document.getElementById('auth').onclick=change;
};
function change(){
this.className="authorised_reporter";
}
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";
}