如何在< td>中获取带有选中标签的元素?标签? [英] How can I get element with checked Label in <td> tag?
本文介绍了如何在< td>中获取带有选中标签的元素?标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在javascipt / jquery中如何获取选中的元素名称。这些都在表格中。我必须到达并检测td标签中已选中复选框的标签。
In javascipt/jquery How can I get checked element name. These are in table. And I have to reach and detect label of checked checkbox in td tag.
$.each(value.Value, function (_, ObjElement) {
var tr = $('<tr>').appendTo(table);
$("<td>").appendTo(tr);
$("<td>", { id: 'clusterList' }).text(ObjElement.Name).append($('<input type=checkbox>').prop("checked", true)).appendTo(tr);
<td id="clusterList">Cluster1<input type="checkbox" checked="checked"></td>
<td id="clusterList">Cluster2<input type="checkbox" checked="checked"></td>
<td id="clusterList">Cluster3<input type="checkbox" checked="checked"></td>
如果选中第一个和第二个复选框,结果应该是这样的。
result should be like that if first and second checkbox are checked.
Listcluster = {Cluster1,Cluster2}
Listcluster={Cluster1,Cluster2}
推荐答案
ID必须是唯一,你应该使用类您可以使用 map
将值存储在数组中方法。
IDs must be unique, you should use classes instead. You can store the values in an array using map
method.
var listCluster = $('table td').has('input[type=checkbox]:checked').map(function(){
return this.textContent || this.innerText;
// return $.trim( $(this).text() );
}).get();
这篇关于如何在< td>中获取带有选中标签的元素?标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文