js选中checkbox的代码,有需要的朋友可以参考下。
<script type="text/javascript">
function getSelectedUsers() {
var sltUser = "";
var arrSelect = document.getElementsByName("myCheckBox");
for (i = 0; i < arrSelect.length; i++) {
if (arrSelect[i].checked) {
sltUser += arrSelect[i].value + ",";
i[0]+=1;
}
}
if (sltUser == "") {
alert("请至少选择一个会员信息!");
return false;
}
else {
document.getElementById("txtSelectedCustomers").value = sltUser;
return confirm('确定要删除?');
}
}
</script>
<input id="myCheckBox" name="myCheckBox" type="checkbox" value="<%#Eval("ID") %>" style=" width:100px;height:50px;" />
protected void delete_Click(object sender, EventArgs e)
{
//string strCheck = this.txtSelectedCustomers.Value;//获取选中值
string[] strCheck = Request.Form["myCheckBox"].ToString().TrimEnd(',').Split(',');//获取选中值
for (int i = 0; i < strCheck.Length; i++)
{
int id = Convert.ToInt32(strCheck[i]);
系统用户表DAInstance().删除用户hzc(id);
}}
<input type="checkbox" name="Checkbox1222" onclick="javascript:selectAll(this.form,this.checked)" />全选。
<script type="text/javascript">
function selectAll(f, mode) {
if (mode == true) {
for (i = 0; i < f.length; i++) {
if (f.elements[i].type == "checkbox") {
f.elements[i].checked = true;
}
}
}
else {
for (i = 0; i < f.length; i++) {
if (f.elements[i].type == "checkbox") {
f.elements[i].checked = false;
}
}
}
}
</script>