首页 新闻 会员 周边

关于Checkboxlist的控制。

0
悬赏园豆:5 [已解决问题] 解决于 2012-04-20 12:50

在我的ASPX 页面上面有一个Checkboxlist 控件被初始化,同时全部item 都是选中状态,我想实现如下效果:

  如果当点击某个ITEM 取消选择的时候,系统提示“是否取消选择” 如果选择是那么就取消选择,如果否就不取消选择。

  对于取消了的选择,如果再次选择的时候,不提示这个对话框。

怎么实现那?

figofeng的主页 figofeng | 初学一级 | 园豆:5
提问于:2012-04-20 11:07
< >
分享
最佳答案
1
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem Selected="True" Text="A" Value="1" />
            <asp:ListItem Selected="True" Text="B" Value="2" />
            <asp:ListItem Selected="True" Text="C" Value="3" />
            <asp:ListItem Selected="True" Text="D" Value="4" />
        </asp:CheckBoxList>
    </div>
    
   
    </form>
    
    <script type="text/javascript">
    
          var inputs = document.getElementsByTagName("input");
          for (var i = 0; i < inputs.length; i++) {
              if (inputs[i].type == "checkbox") {
                  inputs[i].onclick = onCheckBoxClick;
              }
          }

          function onCheckBoxClick() {
              if (!this.checked) {
                  if (confirm("是否取消选择?")) {
                      this.checked = false;
                  } else {
                      this.checked = true;
                  }
              }
              
          }

    </script>
    
</body>
收获园豆:3
Sun.M | 菜鸟二级 |园豆:333 | 2012-04-20 12:08
其他回答(3)
0

Demo:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type="text/javascript">
        window.onload=isUnChecked;
        
        function isUnChecked(){
            var ckb1=document.getElementById("1");
            ckb1.onclick=function(){
                if(this.checked==false){
                    if(confirm("是否取消选择?")){
                        this.checked=false;
                    }
                }
            }
        }
    </script>
</head>
<body>
    <input type="checkbox" checked="checked" id="1">A
    <input type="checkbox" checked="checked" id="2">B
    <input type="checkbox" checked="checked" id="3">C
    <input type="checkbox" checked="checked" id="4">D
</body>
</html>

在线效果:http://jscode.chinacxy.com/code/4ef9924a76abc9730c5394f61caec6c5.aspx

收获园豆:1
artwl | 园豆:16736 (专家六级) | 2012-04-20 11:52
0
<body>
    <form id="form1" runat="server">
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem Selected="True" onclick="if(!this.checked){return confirm('是否取消选择?')}">a</asp:ListItem>
        </asp:CheckBoxList>
    </form>
</body>
收获园豆:1
zernitta | 园豆:235 (菜鸟二级) | 2012-04-20 12:30
0

楼上方法很好啊,用脚本作判断很容易实现的。。。

KivenRo | 园豆:1734 (小虾三级) | 2012-04-20 12:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册