zoukankan      html  css  js  c++  java
  • 当切换select时,获取select选中的值;获取选中的单选按钮的val,判断复选框是否选中

    一、下拉列表

    js:

    $("select").change(function(){
        alert($("select option:selected").val());//再次获取该select的方式获取选中的值
        alert($(this).find("option:selected").text());//使用this的方式获取选中的值
    });

    说明:如果select可以多选则返回一个数组。

    html:select单选

    <body style="height:1000px;">

            <select size="3">
                <option value="1">aaa</option>
                <option value="2">bbb</option>
                <option value="3">ccc</option>
                <option value="4">ddd</option>
                <option value="5">eee</option>
            </select>
        
        </body>

    html:select多选

    <body style="height:1000px;">

            <select size="3">
                <option value="1">aaa</option>
                <option value="2">bbb</option>
                <option value="3">ccc</option>
                <option value="4">ddd</option>
                <option value="5">eee</option>
            </select>
        
        </body>

    二、单选按钮(获取选中按钮的val)

    js:

    alert($("input:radio:checked").val());

    html:

    <form>
    男性:
    <input type="radio" checked="checked" name="Sex" value="male" />
    <br />
    女性:
    <input type="radio" name="Sex" value="female" />
    </form>

    三、复选框(判断是否选中)

    js:

    alert($("input[name='Bike']").prop("checked"));
    alert($("input[name='Car']").prop("checked"));

    html:

    <form>
    我喜欢自行车:
    <input type="checkbox" name="Bike">
    <br />
    我喜欢汽车:
    <input type="checkbox" name="Car">
    </form>

  • 相关阅读:
    Tempter of the Bone HDU
    hihocoder1015 kmp算法
    hihocoder1174 拓扑排序1
    hihocoder1175 拓扑排序2
    Statues CodeForces
    【Git学习】git遇到fatal: bad config line 1 in file C:/Users/lenovo/.gitconfig
    【Windows学习】如何设置程序默认“以管理员身份运行”
    【Python学习】urlparse urllib urllib2 urllib3 requests
    【Python学习】操作excel样例
    【接口测试学习】web和APP接口抓包
  • 原文地址:https://www.cnblogs.com/baoliwei/p/4372176.html
Copyright © 2011-2022 走看看