读书人

CheckBoxList通过js获取Value,该如何解

发布时间: 2012-06-05 13:54:06 作者: rapoo

CheckBoxList通过js获取Value
一开始想到一种方法
foreach (var listItem in backGroundIndustryTreeMods.Select(backGroundIndustryTreeMod => new ListItem(backGroundIndustryTreeMod.Name, backGroundIndustryTreeMod.ID.ToString())))
{
listItem.Attributes.Add("alt", listItem.Value);

chkIndustry.Items.Add(listItem);
}
增加一个Alt属性,这样可以在input前面多一个span可以绑定value,

我需要获取这个id进行异步操作。
但是在提交数据的时候,如果后台的验证没有通过,页面会提交一次,
listItem.Attributes.Add("alt", listItem.Value);
绑定的东西就消失了..请问有没有什么解决方案.?

[解决办法]
在前台验证
[解决办法]
无论成功与否,在重新绑定一次
[解决办法]
使用JQUERY
将CheckBoxList放在div11内
$("#div11 :checkbox").bind("click", function () {
var s = $(this).next();
alert(s.html());
});

$(this).next(); 通过这个方法可以获取复选框后面对应的LABEL元素

读书人网 >asp.net

热点推荐