我有一个动态生成的 asp.net 复选框列表,如果复选框最初被选中并且未选中,我需要处理一些代码。
这需要在 Jquery 或 Javascript 中完成。
我看到的所有示例都处理获取“已检查”的所有值我只对获取触发 onClick() 事件 ID 的特定项目感兴趣,以便我可以运行一些其他代码来处理它。
public void DrawPoolWeekCbList()
{
var poolWeeks = ControllerFacade.GetAllPoolWeeksByPoolYear(PageView.PoolWeekYear.Text);
var pWeekCount = poolWeeks.Count;
var curRecord = 0;
foreach (var poolWeek in poolWeeks)
{
PageView.cblPoolWeeks.Items.Add(poolWeek);
PageView.cblPoolWeeks.Items[curRecord].Attributes.Add("onclick", "OnCheckBoxClicked("+ poolWeek +")");
curRecord++;
}
}
//UI Code
function OnCheckBoxClicked(poolWeek) {
var chkId = poolWeek.toString();
$('#<%= lblPoolWeekChange.ClientID %>').text(chkId);
$(".addNew").dialog("open");
}
我见过的所有示例都找到了所有选中的复选框并循环遍历它们,我再次只想要触发该功能的特定复选框 id。
谢谢!
//Generated HTML -
<input id="ContentPlaceHolder1_cblPoolWeeks_0" type="checkbox" name="ctl00$ContentPlaceHolder1$cblPoolWeeks$0" onclick="OnCheckBoxClicked(01);" value="01" /><label for="ContentPlaceHolder1_cblPoolWeeks_0">01</label></td><td><input id="ContentPlaceHolder1_cblPoolWeeks_1" type="checkbox" name="ctl00$ContentPlaceHolder1$cblPoolWeeks$1" onclick="OnCheckBoxClicked(02);" value="02" /><label for="ContentPlaceHolder1_cblPoolWeeks_1">02</label></td><td><input id="ContentPlaceHolder1_cblPoolWeeks_2" type="checkbox" name="ctl00$ContentPlaceHolder1$cblPoolWeeks$2" onclick="OnCheckBoxClicked(03);" value="03" /><label for="ContentPlaceHolder1_cblPoolWeeks_2">03</label>