gpt4 book ai didi

javascript - 如何调用td的id改变css样式onclick

转载 作者:行者123 更新时间:2023-11-28 12:59:55 25 4
gpt4 key购买 nike

下面是我使用 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";
document.getElementById('main').className="authorised_reporter";

}

关于javascript - 如何调用td的id改变css样式onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16223476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com