<asp:CheckBoxList runat="server" ID="listTest"> </asp:CheckBoxList> <input type="button" id="btnShow" value="显示选中值" />
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
//分别为text值、value值
listTest.Items.Add(new ListItem(dr["Title"].ToString(), dr["ID"].ToString()));
}
}
<table id="listTest" border="0">
<tr>
<td>
<input id="listTest_0" type="checkbox" name="listTest$0" />
<label for="listTest_0">基于jQuery的一个震动效果</label>
</td>
</tr>
<tr>
<td><input id="listTest_1" type="checkbox" name="listTest$1" />
<label for="listTest_1">使用css的overflow属性改变缩略图大小</label>
</td>
</tr>
</table>
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
//分别为text值、value值
listTest.Items.Add(new ListItem(dr["Title"].ToString(), dr["ID"].ToString()));
}
//为ListItem对象添加alt属性,值保存value值
foreach (ListItem li in listTest.Items)
{
li.Attributes.Add("alt", li.Value);
}
}
<table id="Table1" border="0">
<tr>
<td>
<span alt="400"><input id="listTest_0" type="checkbox" name="listTest$0" />
<label for="listTest_0">基于jQuery的一个震动效果</label></span>
</td>
</tr>
<tr>
<td><span alt="398"><input id="listTest_1" type="checkbox" name="listTest$1" />
<label for="listTest_1">使用css的overflow属性改变缩略图大小</label></span>
</td>
</tr>
</table>
$(document).ready(function() {
$("#btnShow").click(function() {
var valuelist = ""; //保存checkbox选中值
//遍历name以listTest开头的checkbox
$("input[name^='listTest']").each(function() {
if (this.checked) {
//$(this):当前checkbox对象;
//$(this).parent("span"):checkbox父级span对象
valuelist += $(this).parent("span").attr("alt") + ",";
}
});
if (valuelist.length > 0) {
//得到选中的checkbox值序列,结果为400,398
valuelist = valuelist.substring(0, valuelist.length - 1);
}
});
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有