C# 使用Jquery从动态html表列获取复选框的Id
在我的网页上,我使用 c#函数C# 使用Jquery从动态html表列获取复选框的Id,c#,jquery,html,asp.net,C#,Jquery,Html,Asp.net,在我的网页上,我使用 c#函数 public String TableForView(DataTable ViewTable) { StringBuilder html = new StringBuilder(); try { if (ViewTable.Rows.Count > 0) { html.Append("<table id='shTabl
public String TableForView(DataTable ViewTable)
{
StringBuilder html = new StringBuilder();
try
{
if (ViewTable.Rows.Count > 0)
{
html.Append("<table id='shTable' class='table table-striped table-bordered'>");
html.Append("<thead>");
html.Append("<tr>");
foreach (DataColumn column in ViewTable.Columns)
{
html.Append("<th>");
html.Append(column.ColumnName);
html.Append("</th>");
}
html.Append("<th>");
html.Append("Action & View");
html.Append("</th>");
html.Append("</tr>");
html.Append("</thead>");
html.Append("<tbody>");
foreach (DataRow row in ViewTable.Rows)
{
html.Append("<tr>");
foreach (DataColumn column in ViewTable.Columns)
{
html.Append("<td>");
html.Append(row[column.ColumnName]);
html.Append("</td>");
}
html.Append("<td>");
html.Append("<input type='checkbox' id='" + row["AccNo"] + "' name='" + row["AccNo"] + "' class='ChBoxVal' checked=''>");
html.Append("</td>");
}
html.Append("</tbody>");
html.Append("</table>");
}
else
{
html.Append("<h4>NO DATA AVAILABLE</h4>");
}
}
catch (Exception ex)
{
Error_ManagerClass em = new Error_ManagerClass();
em.WriteError(ex);
}
return (html.ToString());
}
但此函数不返回任何值。我对jquery有点陌生,我不知道这是否是编写jquery函数的正确方法
请帮助我找到一个解决方案,或者告诉我在哪里可以找到这个解决方案 使用
输入[type=“checkbox”]
选择复选框,然后仅按如下方式进行筛选:
$.each("#shTable tbody tr td input[type=checkbox]:checked",function(index,element){
var $checkBox = $(element);
var $checkBoxId = $checkBox.attr('id');
// you will get everything about the checkbox
});
var getChecked=function(){
返回$('#shTable').find('input[type=“checkbox”]”)
.filter(“:选中”)
.toArray()
.map(函数(x){
返回$(x).attr('id');
});
}
$(文档).on('单击','获取ID',函数(){
log(getChecked());
});代码>
一个
两个
三
四
获取ID
使用$(文档)。查找('input:checkbox:checked')
对于动态生成的元素我尝试过,警报(arrayOfValues)没有显示任何内容。。!!给你的答案加上一些解释以便更好地理解
$.each("#shTable tbody tr td input[type=checkbox]:checked",function(index,element){
var $checkBox = $(element);
var $checkBoxId = $checkBox.attr('id');
// you will get everything about the checkbox
});