需求:Repeater中嵌套了一个Repeater,子Repeater中每行有个CheckBox,想用js实现每个子Repeater中的 CheckBox单选,或者不选。
就是每个子Repeater中的CheckBox不能多选。哪位给个思路,或者给个好用的 js。小弟拜谢了。
就是每个子Repeater中的CheckBox不能多选。哪位给个思路,或者给个好用的 js。小弟拜谢了。
解决方案 »
- 如何在不用代码的情况下,转移网站文件到另一台机子上顺利运行,不需要另外调试?
- 如下 顶贴者有赏
- 请问怎么样把数据库中一列项的数据写入数组?
- 如何存储日期型数据为null?在线给分
- XmlHttpRequest的status是0
- 求助:基于.net,salt,实现模拟语音操作系统--方法,资料...重谢!!
- 外网企业邮箱
- 请问在加拿大有哪些比较好的ASP.NET空间供应商?强烈请求帮忙!
- 谁有二级域名的解决方案?或者谁做过。
- -----------------------程序打包后到服务器安装出现的错误----------------
- asp.net (vb) 一打开网页怎样让光标定在TextBox中,谢谢
- 图片
{
for(var i=0;i<form1.elements.length;i++)
{
var e = form1.elements[i];
if(e.type!=null && e.type=="checkbox" && e.parentElement.parentElement.parentElement.parentElement.id=="tab") //表格里的所有checkbox是否全部选种
{
if(e.checked)
{
e.checked = false;
chk.checked = true;
}
}
}
}
引用jquery包
window.selAll=function(obj)
{
$("input[name='chk_Sel']").attr("checked",$(obj).attr("checked"));
} <td width="80px" align="center">
<input type="checkbox" name="chk_Sel" id="chk_Sel" value='<%# Eval("id") %>'/>
</td>
操作按钮input type=checkbox id="Checkbox1" name=Checkbox1 nclick="SelectAll();"
选择对象input type=checkbox id=ckb name=ckb value=runat=server遍历选中按钮string arrid="";
string a="";
foreach (RepeaterItem item in AdminList.Items)
{
HtmlInputCheckBox chkbox1=(HtmlInputCheckBox)item.FindControl("ckb");
if (chkbox1.Checked==true)
{
arrid+=chkbox1.Value+",";
a+=chkbox1.Value;
}
}
if(a.Length==0)
{
Response.Write("<script>alert('请选择短信息');window.location.href='noteManage.aspx?g=notelist';</script>");
return;
}
arrid=arrid.Substring(0,arrid.Length-1);
string[] id=arrid.Split(',');
if(id.Length>=1)
{
for(int i=0;i<id.Length;i++)
{
DB.Note_Delete(id[i].Trim(),2);
}
Response.Write("<script>alert('短信息删除成功');window.location.href='noteManage.aspx?g=notelist';</script>");
}
function hs(){
var a = document.getElementsByName("chkStudent");
var j=0;
for(var i=0;i<a.length;i++){
if(a[i].checked){
j=j+1;
if(j>1){
alert("只能选择一个角色");
return false;
}
alert(a[i].value);
}
}
if(j==0){
alert("请选择角色!");
return false;
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Test_Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><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" >
$(function()
{
$('table[id*=rep_child] input[id*=ckb_sel]').click(function()
{
$(this).parent().parent().find('input[id*=ckb_sel]:checked').attr("checked",false);
$(this).attr("checked",!this.checked);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rep_parent" runat="server" OnItemDataBound="rep_parent_ItemDataBound">
<ItemTemplate>
<table border="1">
<tr>
<td><asp:Label ID="Label1" style="width:80px;" runat="server" Text="<%# bind('a') %>"></asp:Label></td>
<td><asp:Label ID="Label2" style="width:80px;" runat="server" Text="<%# bind('b') %>"></asp:Label></td>
<td><asp:Label ID="Label3" style="width:80px;" runat="server" Text="<%# bind('c') %>"></asp:Label></td>
<td><asp:Label ID="Label4" style="width:80px;" runat="server" Text="<%# bind('d') %>"></asp:Label></td>
</tr>
</table>
<asp:Repeater ID="rep_child" runat="server">
<ItemTemplate>
<asp:Label ID="lbl_child" runat="server" Style="width: 80px;" Text="<%# bind('id') %>"> ></asp:Label>
<table border="1">
<tr><td><asp:CheckBoxList id="ckb_sel" runat="server" RepeatDirection="Horizontal"><asp:ListItem>test1</asp:ListItem>
<asp:ListItem>test2</asp:ListItem>
<asp:ListItem>test3</asp:ListItem>
<asp:ListItem>test4</asp:ListItem>
</asp:CheckBoxList> </td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
<br />
<br />
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Test_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("a");
dt.Columns.Add("b");
dt.Columns.Add("c");
dt.Columns.Add("d");
for (int i = 0; i < 10; i++)
{
System.Data.DataRow dr = dt.NewRow();
foreach (System.Data.DataColumn dc in dt.Columns)
{
dr[dc.ColumnName] = "test" + i.ToString();
}
dt.Rows.Add(dr);
}
rep_parent.DataSource = dt.DefaultView;
rep_parent.DataBind(); }
}
protected void rep_parent_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Repeater rep_child=e.Item.FindControl("rep_child") as Repeater;
DataTable dt = new DataTable();
dt.Columns.Add("id");
DataRow dr = dt.NewRow();
dr[0] = e.Item.ItemIndex+1;
dt.Rows.Add(dr); rep_child.DataSource = dt;
rep_child.DataBind();
}
}
{
var objtb = document.getElementById(cb);
list = objtb.getElementsByTagName("INPUT");
var num = 0;
for(var i =0;i<list.length;i++)
{
if(list[i].checked)
{
num = num+1;
}
if(num>3)
{
alert("科室的选择不得超过3个!");
list[i].checked = false;
return false;
}
}
}
<script type="text/javascript">
var num = 0;
function Limit(chbControl)
{
if(chbControl.checked == true)
{
if(num>=5)
{
chbControl.checked = false;
alert('不能超过5条!');
}
else
{
num++;
}
}
else
{
num--;
}
}
</script>