【发布时间】:2023-03-09 10:15:02
【问题描述】:
我正在使用 jquery/数据表。我想突出显示数据表中的选定行。有实现它的示例 jQuery 代码。这是代码
var oTable;
var giRedraw = false;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Init the table */
oTable = $('#example').dataTable( );
我所做的是将代码复制到 test.js 文件中并导入。但是,它不起作用。我什至尝试将 $ 更改为 jQuery,但它仍然不起作用。我已经设置了 configuration.add(JQuerySymbolConstants.SUPPRESS_PROTOTYPE, "false");在我的 AppModule 中。如何将 Jquery 与 Tapestry 一起使用?
任何帮助将非常感激。谢谢。
【问题讨论】:
-
我认为问题出在包含
id的html上。#example,尝试在这里粘贴你的html代码.. -
我将 id #example 更改为我的 id #tableList,但它不起作用。
-
如果将 JQuerySymbolConstants.SUPPRESS_PROTOTYPE 设置为 false,则不能对 jQuery 使用 '$',但需要使用 '$j'。您可以使用 JQuerySymbolConstants.JQUERY_ALIAS 设置自己的别名
-
我也尝试过使用 $j 但它不起作用。
-
你确定你的 JavaScript 代码真的被调用了吗?你是怎么把它包括在内的?如果您使用 @Import 或 JavaScriptSupport.importJavaScriptLibrary() 包含它,则无需将代码包装在 $(document.ready(function(){...}) 中,因为 Tapestry 已经为您做到了。另外,您只是说它不起作用,但没有提到任何 JavaScript 错误。