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

标签 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_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/

相关文章:

javascript - 在 D3.js 中创建从 01JAN15 -> 31DEC15 的垂直时间线

javascript - 根据第 1 个 2 个下拉列表 ID 显示第 3 个下拉列表

javascript - jQuery 如何检测文件当前是否正在上传(事件正在运行)

javascript - 如何将其设置为 "save as HTML"而不是 "download as HTML"?

HTML 5 Doctype 打乱布局

html - 最后一个 child /最后一个类型不适用于 div

javascript - 如何使 xPages 名称选择器显示公司目录或扩展目录目录名称?

javascript - 使用 HTML 和 javascript 制作在线计算器

javascript - 在 html 中使用 jquery/javascript/css 进行表过滤、排序、不同记录

javascript - 如何根据下拉选项列表中的选定值过滤 div?