zoukankan      html  css  js  c++  java
  • jquery的radio的change事件

    一、用的jquery的radio的change事件:当元素的值发生改变时,会发生 change 事件,radio选择不同name值选项的时候恰巧是值发生改变

    表单单选框

    <input type="radio" name="bedStatus" id="allot" checked="checked" value="allot">Allot

    <input type="radio" name="bedStatus" id="transfer" value="transfer">Transfer

    $(document).ready(function() {
       // jquery的radio的change事件 $(
    'input[type=radio][name=bedStatus]').change(function() { if (this.value == 'allot') { alert("Allot Thai Gayo Bhai"); } else if (this.value == 'transfer') { alert("Transfer Thai Gayo"); } }); });
    
    

    1. 获取radio选中的value.

      $('input:radio[name=bedStatus]:checked').val();

    2. 选择 radio 按钮(这里的下标取决于有几个name为bedStatus的按钮)

    $('input:radio[name=bedStatus]:nth(0)').attr('checked',true);
    或者
    $('input:radio[name=bedStatus]')[0].checked = true;

    3. 重置 radio 按钮.

    $('input:radio[name=bedStatus]').attr('checked',false);

    二、jquery的change事件

     <input type="radio" name="bedStatus" class="symbols_radio" checked="checked" value="allot">Allot

    <input type="radio" name="bedStatus" class="symbols_radio" value="transfer">Transfer

       $(function () {
            $(".symbols_radio").change(function () {
               console.log(this.value);  // allot
               console.log(this.name);  // bedStatus
        });

    三、jquery的click事件:监听type=radio的click事件

    $(':radio').clcik(function(){
        var value = $(this).vale()  //获取选中的radio的值
    });
  • 相关阅读:
    全栈的苦逼和崛起
    Swift内部类调用外部类方法、属性的变通
    Assets.xcassets误删后的恢复
    UITableViewCell嵌套UITableView的正确姿势
    GPU Accelerated Computing with Python
    Windows 10创意者更新ISO发布!官方下载
    Amazing iOS Tips
    self-sizing cell的一个问题
    buf.swap32()
    buf.swap16()
  • 原文地址:https://www.cnblogs.com/niuben/p/12558841.html
Copyright © 2011-2022 走看看