我正在嘗試使用 JQuery 在單擊時切換 html 表行的類“突出顯示”。該表是使用 Django 模板語言創建的。該表可以工作并顯示在我的開發服務器中,而 Jquery 可以處理不是用 Django 模板語言創建的表。運行代碼時我沒有收到任何錯誤,但是當我單擊表格行時它沒有做任何事情。我不確定問題可能是什么。HTML<style media="screen"> .highlight { background-color: yellow; color: white; }</style><div class="table-responsive"> <table class="table table table-borderless" id="food_table"> <thead> <tr> <th>#</th> <th>Description</th> <th>Price</th> </tr> </thead> <tbody> {% for order in orders %} <tr> <td>{{ order.pk }}</td> <td>{{ order.Price }}</td> <td>{{ order.Description }}</td> </tr> {% endfor %} </tbody> </table></div>查詢$("#food_table tbody").on('click','tr',function() { $(this).toggleClass("highlight"); });虛擬數據[ { "pk": 9, "Description": "Pizza", "Price": "88.00" }, { "pk": 10, "Description": "Steak", "Price": "130.50" }, { "pk": 11, "Description": "Coca Cola", "Price": "25.95" }, { "pk": 12, "Description": "Water", "Price": "15.00" }]
Jquery在單擊時選擇表行不起作用
慕森王
2021-12-12 16:08:31