选择符合条件的表

jQuery Select tables that match criteria

本文关键字:条件 选择      更新时间:2023-09-26

我有一个表,在这个表中,每个条目都有子表。每一项都是$item。所讨论的UI是一个搜索工具,可用于通过ajax将"选定"项目列表发送给邮件功能。

但是,当我单击复选框并选择send时,这只会获得一个表的HTML,而不是所有选中的表。

jQuery('#search-query-send').click(function(){
  jQuery('.apartment-entry:has(:checked)').each(function(){
    var content = jQuery(this).html()
    console.log(content);
  });
});

看我的小提琴

我想能够console.log()的HTML为每个表我已经选择。

你几乎选对了选择器

jQuery('#search-query-send').click(function() {
    jQuery('.selectthis input:checked').each(function() {
    var content = jQuery(this).parents('table').html();
    console.log(content);
  });
});
http://jsfiddle.net/9d1pgjv8/7/

你必须target selectthis class这样它就会得到复选框文本或值或任何你想要的。

$('#search-query-send').click(function(){
	$('.apartment-entry .selectthis:has(:checked)').each(function(){
		var content = $(this).text()
		console.log(content);
	});
});