Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何呼叫td';s id更改css样式onclick_Javascript_Html_Css - Fatal编程技术网

Javascript 如何呼叫td';s id更改css样式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

下面是我使用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_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";
}