<!--
RadioButton 操作

$("input[type=radio]:checked").val() 取得选中项的值(单选)

$("input[name=names]").val("[set_values]"); 设置选中的值

同样适用于Checkbox/Select等

-->
<!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>
    <title>RadioButton操作</title>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //RadioButton
            $("#getSex").click(function () {
                alert($("input:radio[name=sex]:checked").val());
            });

            $("#setSex").click(function () {
                $("input:radio[name=sex]").val(["unknow"]);
            });

            //CheckBox
            $("#getWhere").click(function () {
                var tips = "你选择了:\n";
                $("input:checkbox[name=where]:checked").each(function () {
                    tips += $(this).val() + "\n";
                });
                alert(tips);
            });

            $("#setWhere").click(function () {
                $("input:checkbox[name=where]").val(["搜索引擎", "朋友介绍"]);
            });
        });
    </script>
</head>

<body>
    <input name="sex" type="radio" value="man" />man<br />
    <input name="sex" type="radio" value="woman" />woman<br />
    <input name="sex" type="radio" value="unknow" />unknow<br />

    <input id="getSex" type="button" value="取值" />
    <input id="setSex" type="button" value="设值" />

    <hr />

    你从哪里找我们:<br />
    <input name="where" type="checkbox" value="搜索引擎" />搜索引擎<br />
    <input name="where" type="checkbox" value="朋友介绍" />朋友介绍<br />
    <input name="where" type="checkbox" value="网站推荐" />网站推荐<br />
    <input name="where" type="checkbox" value="无意进入" />无意进入<br />

    <input id="getWhere" type="button" value="取值" />
    <input id="setWhere" type="button" value="设值" />
</body>
</html>