Getting Value from switch

This question already has an answer here:

  • How to check whether a checkbox is checked in jQuery? 56 answers

  • You can use the native javascript way

    var isChecked = this.checked;
    

    or the jQuery .prop

    var isChecked = $(this).prop("checked");
    

    看看这个:

     $('[type="checkbox"]').click(function(e) {
       var isChecked = $(this).is(":checked");
       console.log('isChecked: ' + isChecked);
       $("#switchText").html(isChecked?'Yes checked':'No checked');
     });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <label class="switch">
      <input id="mySwitchCheckbox" type="checkbox" /><span id="switchText">Check-me</span></label>
    链接地址: http://www.djcxy.com/p/9532.html

    上一篇: 如何检查复选框是否被选中?

    下一篇: 从交换机获得价值