我想用一個特定的ID來標記行,在我的例子中是id=oneX
。 我嘗試以下如何在表中爲一行創建紅色背景?
<html>
<body>
<script src="http://www.ajax.googleapis.com/ajax/libs/jquery/1.11.1/qjuery.min.js">
</script>
<script>
function makeRed() {
$("tr#oneX").attr("background-color","red");
}
</script>
<table>
<tr id="oneX"><td>test1</td></tr>
<tr id="twoX"><td>test2</td></tr>
<button onclick="makeRed()">Make Red</button>
</table>
</body>
</html>
但不能使它工作
在純JS你會這樣做:'document.getElementById('oneX')。style.backgroundColor ='red''。 – RobG