62,046
社区成员
发帖
与我相关
我的任务
分享
<asp:TextBox ID="txt_pjName" runat="server">
</asp:TextBox><div id='divCheck' style="border: 1px dotted #A7A6AA; display: none; cursor: pointer;
height: 100px; overflow:auto; z-index: 10000; background:#FFFFFF">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="2">
</asp:CheckBoxList>
</div>
void BindName()
{
string sql = "select engName from userinfo";
DataSet ds = SqlHelper.GetDS(sql);
this.CheckBoxList1.DataSource = ds;
this.CheckBoxList1.DataValueField = "UserName";
this.CheckBoxList1.DataTextField = "UserName";
this.CheckBoxList1.DataBind();
this.ddlWorker.Items.Insert(0, new ListItem("", ""));
}
$("td > span > input").click(function(){
var arr=[];
$("#CheckBoxList1 :checkbox:checked").each(function(){
。。。
$(document).ready(function(){
var chks = $("input[id^='<%=CheckBoxList1.ClientID%>']:checkbox");
chks.click(function(){
$("#txt_pjName").val(chks.find(":checked").val() || []).join(","));
});
});
$("#txt_pjName").val(
$("input[id^='<%=CheckBoxList1.ClientID%>']:checkbox:checked").val() || [])
.join(",")
);
$("#txt_pjName").val(
$("input[id^='CheckBoxList1']:checkbox:checked").val() || [])
.join(",")
);
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#getText").click(function(){
var arr=[];
$("#CheckBoxList1 :checkbox:checked").each(function(){
arr.push($(this).next().html());
})
$("#txt_pjName").val(arr.join(','));
})
$("#getValue").click(function(){
var arr=[];
$("#CheckBoxList1 :checkbox:checked").each(function(){
arr.push($(this).parent().attr("SetValue"))
})
$("#txt_pjName").val(arr.join(','));
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txt_pjName" runat="server">
</asp:TextBox>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="2"
ondatabound="CheckBoxList1_DataBound">
</asp:CheckBoxList>
<a id="getText">获取文本</a>
<a id="getValue">获取值</a>
</form>
</body>
</html>
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
ListControl list = sender as ListControl;
foreach (ListItem item in list.Items)
{
item.Attributes["SetValue"] = item.Value;
}
}
$(function(){
$("input[id^='CheckBoxList1']").click(function(){
$("input[id^='CheckBoxList1']").each(function() {
if($(this).attr("checked")){
alert($(this).val());
}
});
});
});
$(function(){
$("#cblist > input").click(function(){
var str=[];
$("input").each(function() {
if($(this).attr("checked")){
str.push($(this).val());
$("#txt_pjName").val(str.join(","));
}
});
});
});
<div id="cblist">
<input type="checkbox" id="cb1" name="cb" value="111" />hi<br />
<input type="checkbox" id="cb2" name="cb" value="222" />hello<br />
<input type="checkbox" id="cb3" name="cb" value="333" />c#<br />
<input type="checkbox" id="cb4" name="cb" value="444" />linux<br />
</div>