我在gridview上有一个用于筛选文本框的脚本,在每一行上有一个用于复选框的脚本。当我在网格中过滤某物时,我会得到一些过滤过的行。我想使用选择脚本来选择那些过滤过的行。但是它是在网格中选择所有的结果。
选中复选框脚本:
$("#<%=gvCheckDetails.ClientID%> input:checkbox").live("click", function(event) {
var tbl = $("#<%=gvCheckDetails.ClientID%>");
var checkbox = $(this);
var checkState = checkbox.is(":checked");
var ancestorName = checkbox.parent().parent()[0].nodeName; // tr or th?
// if it's a header, we'll work with all rows (select on or off)
if (ancestorName.toLowerCase() === "th") {
$(tbl[0].config.rowsCopy).each(function() {
if (checkState)
$(this).find("input:checkbox").attr('checked', true);
else
$(this).find("input:checkbox").removeAttr('checked');
});
}
});
有谁能帮我修改上面的脚本,以便在选中selectall时只选择筛选过的值(搜索文本框是使用aspx中的jscript动态过滤网格行)
发布于 2013-08-28 06:56:07
基于的 Augusto Men 答案:
刚刚换了
$(this).find("input:checkbox").attr('checked', true);
使用
$(this).filter(':visible').find("input:checkbox").attr('checked', true);
因此,现在复选框检查是过滤和应用仅访问的。
非常感谢Augusto
发布于 2013-08-27 13:39:48
:visible
选择器通常会完成这个任务。它只过滤可见的元素,包括DOM中的父元素。
$(tbl[0].config.rowsCopy).filter(':visible').each(function() {
https://stackoverflow.com/questions/18475236
复制相似问题