日期:2014-05-17 浏览次数:20473 次
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") + ",";
}
});