作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要一个(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/
我是一名优秀的程序员,十分优秀!