【发布时间】:2015-01-14 05:07:30
【问题描述】:
我正在使用 C# 代码动态创建复选框并将它们添加到占位符,我使用 Jquery 在鼠标悬停事件上选中/取消选中它们。
C#:
for (j = d; j < b; j++) {
plhdr_seat.Controls.Add(new LiteralControl("<td>"));
// CheckBox fg = new CheckBox();
plhdr_seat.Controls.Add(new LiteralControl("<td>"));
HtmlInputCheckBox cb = new HtmlInputCheckBox();
cb.Attributes.Add("class", "mew");
cb.Checked = true; // or cb.Checked = false;
cb.ID = "check_" + j.ToString();
plhdr_seat.Controls.Add(cb);
plhdr_seat.Controls.Add(new LiteralControl("</td>"));
}
jquery:
<script>
$(document).ready(function () {
$(".mew").mouseover(function () {
var attr = $(this).attr("Checked");
if (typeof attr !== typeof undefined && attr !== false)
{
$(this).prop('checked', false); // will check the checkbox with id check1
}
else {
$(this).prop('checked', true); // will uncheck the checkbox with id check1
}
});
});
</script>
我有这个。
悬停时复选框未选中。但是我再次将鼠标悬停在它们上,它们没有被检查。 我无法确定问题所在。请帮帮我。
【问题讨论】:
标签: c# jquery html asp.net checkbox