我想實現一個JavaScript,它將突出顯示在click.HTML表中的列的列。作爲下面的行高亮的工作示例,我試圖使用相同的table.columns但table.columns不存在。是任何是要突出使用jQuery的HTML表中的列?如何使用js或jquery突出顯示html表中的列單擊?
工作代碼高亮行: 表高亮POC
<script>
function highlight() {
var table = document.getElementById('dataTable');
for (var i = 0; i < table.rows.length; i++) {
table.rows[i].onclick = function() {
if (!this.hilite) {
this.origColor = this.style.backgroundColor;
this.style.backgroundColor = '#BCD4EC';
this.hilite = true;
}
else {
this.style.backgroundColor = this.origColor;
this.hilite = false;
}
}
}
}
</script>
<style>
table {
border-spacing: 0px;
}
td {
border: 1px solid #bbb;
padding: 0.2em;
}
</style>
</head>
<body>
<table id="dataTable">
<tr onclick="highlight()"><td>Data1</td><td>Data2</td></tr>
<tr onclick="highlight()"><td>Data1</td><td>Data2</td></tr>
<tr onclick="highlight()"><td>Data1</td><td>Data2</td></tr>
</table>
</body>
</html>
[Here](http://stackoverflow.com/questions/14061123/jquery-selector-to-grab-cells-in-the-same-column)您可以看到如何從點擊的同一列中選擇所有單元格。然後,您需要做的就是將backgroundColor設置爲所有這些單元格。 – TheWanderingMind
您的問題是關於突出顯示列,但您的代碼似乎建議嘗試選擇行。你想要做的是哪一項? –