[英]how to change the background color of row when selected in javascript
[英]Change color row Datatable selected when click on button Javascript
單擊“應用”按鈕時,我需要更改數據表中一行的顏色
這是我的行的 HTML 代碼:
<tr role="row" class="odd"></tr>
<tr role="row" class="even selected"></tr>
<tr role="row" class="odd"></tr>
<tr role="row" class="even"></tr>
在我的檢查選項卡中,我可以像這樣更改行的背景顏色:
table.dataTable tbody tr.selected {
background-color: orange;
}
如何在 Javascript 中編碼? 我試過這段代碼,但我得到了一個錯誤:
$("#btnApply").click(function() {
var zz = document.getElementsByClassName("selected");
zz.style.backgroundColor = "orange";
});
錯誤 :
未捕獲的類型錯誤:無法設置未定義的屬性“backgroundColor”
當您在第一行中使用 jQuery 時,Y 不要像這樣繼續使用它:
$("#btnApply").click(function() { $(".selected").css('background-color', 'green'); });
table tr.selected { background-color: orange; }
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <table> <tr role="row" class="odd"><td>aa</td></tr> <tr role="row" class="even selected"><td>aa</td></tr> <tr role="row" class="odd"><td>aa</td></tr> <tr role="row" class="even"><td>aa</td></tr> </table> <input type="button" id="btnApply" value="click">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.