【问题标题】:How know if BootStrap Radio Button is Checked? [duplicate]如何知道 BootStrap 单选按钮是否被选中? [复制]
【发布时间】:2017-01-03 11:19:53
【问题描述】:

我需要测试 BootStrap 单选按钮是否被选中。 这是我的方法,但它不起作用。 如何验证单选按钮是否已选中?

<script>
    function optChange() {
          if (document.getElementById("optEventType").val() == 'yes'){
            /// Do something.....
           }
    }
</script>

<form>
   <div id ="optType" onchange="optChange()" class="radio">
        <label><input type="radio" name="opt1" id = "opt1">Tex21 </label>
        <label><input type="radio" name="opt1" id = "opt2">Text2</label>
    </div>
</form>

【问题讨论】:

    标签: javascript jquery twitter-bootstrap


    【解决方案1】:
    if ($("#opt1").is(":checked"))) {
      // do A
    }
    
    else if ($("#opt2").is(":checked")) {
      // do B
    }
    

    您在这里也有类似的答案:jQuery, checkboxes and .is(":checked")

    但我看到您在选项中使用了 ids 属性,所以我将其用于您的答案..

    【讨论】:

      猜你喜欢
      • 2014-11-05
      • 2012-10-22
      • 2017-09-14
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多