gpt4 book ai didi

jquery - 在表格单元格内的任意位置选择一个复选框

转载 作者:行者123 更新时间:2023-12-01 08:13:09 25 4
gpt4 key购买 nike

我需要一个(jQuery)选择器,上面写着:

Anytime there's a checkbox inside a table cell, then make the cursor a pointer for that table cell and if the user clicks anywhere inside the table cell, then click the checkbox for them.

我想我曾经有过这个,但那是在“on”选择器出现之前,而且,我认为它在某个时候让我陷入了无限循环的麻烦,所以我把它拿出来了。

最佳答案

这样就可以了。我使用 td 进行事件委托(delegate),因为可能有大量的 table,而且它还使您可以灵活地在将来通过 JavaScript 和让他们正常工作

// Get some references to your elements.
var $table = $("#some-table");
var $tdWithCheckbox = $table.find("td:has(input[type='checkbox'])");

// Alternatively, add a class which has `cursor: pointer`.
$tdWithCheckbox.css("cursor", "pointer");

// Use event delegation.
$table.on("click", "td", function() {
$(this).find("input[type='checkbox']").prop("checked", true);
});

关于jquery - 在表格单元格内的任意位置选择一个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12241414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com