zoukankan      html  css  js  c++  java
  • JQuery[10] RadioButton/CheckBox/Select操作

    <!--
    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>
    

      

    My New Blog : http://blog.fdlife.info/ The more you know, the less you believe.
  • 相关阅读:
    jquery 实现跨域的简单小例子;
    jquery 实现文字轮播滚动
    js jquery 上传文件格式大小判断简单总结
    js 文本编辑插件 wangEditor 的使用教程和总结
    vue项目结构介绍
    bootstrap select下拉框模糊搜索和动态绑定数据解决方法
    bootstrap实现下拉框select option 美爆了
    jquery 获得select下拉框选择中的属性值
    Nginx + uWSGI 配置django---终极版
    django全文检索
  • 原文地址:https://www.cnblogs.com/ForDream/p/2134490.html
Copyright © 2011-2022 走看看