复选框、单选框 jquery判断是否选中Demo

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="eachcheckbox.aspx.cs" Inherits="WebApplication1.eachcheckbox" %>

<!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 src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {
            var cnt = 0;
            var sel = '';
            $("#btnclick").click(function () {
                //debugger;
                var items = jQuery("input:checked[guid]");
                items.each(function () {
                    if (jQuery(this).attr("guid")) {

                        sel += "," + jQuery(this).attr("guid");
                        cnt += 1;
                    }
                    else {

                    }
                });


                if (cnt < 1) {
                    alert('请选择记录!');
                    return false;
                } else {
                    // if (confirm('确定要删除吗?')) {
                    alert(sel);
                    // }
                }
                sel = "";

            });//获取选中的是哪一个

            $("#chkIsPublic").click(function () { //对单选按钮单击
                var ss = $('input:radio:checked').val();
                alert(ss);
            });
        });

        //复选框全选
        function aa(obj) {

            $(".checkBox>input").attr("checked", $(obj).attr("checked"));
            $(".checkBox").attr("checked", $(obj).attr("checked"));
        }
       
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input type="button" id="btnclick" value="获取选中的是哪一个" />
    
    <div>
        <table>
        <tr>
           <td colspan="3"><input type="checkbox" id="checkAll" onclick="aa(this)" />全选</td>
        </tr>
            <tr>
                <td>
                    <input type="checkbox" id="chkguid" guid="class1" class="checkBox" />班级1
                </td>
                <td>
                    <input type="checkbox" id="Checkbox1" guid="class2" class="checkBox" />班级2
                </td>
                <td>
                    <input type="checkbox" id="Checkbox2" guid="class3" class="checkBox" />班级3
                </td>
            </tr>
        </table>
    </div>
    <div>
        ----------------------------------------------------------------------------------------------
    </div>
    <asp:RadioButtonList ID="chkIsPublic" runat="server" RepeatDirection="Horizontal"
        RepeatLayout="Flow" RepeatColumns="5">
        <asp:ListItem Value="0" Selected="True">租赁</asp:ListItem>
        <asp:ListItem Value="1">购买</asp:ListItem>
        <asp:ListItem Value="2">代理商</asp:ListItem>
    </asp:RadioButtonList>
    </form>
</body>
</html>

 

posted @ 2014-02-27 14:51  Jbp  阅读(336)  评论(0编辑  收藏  举报