【问题标题】:Jquery value of checkbox always return on [duplicate]复选框的Jquery值总是返回[重复]
【发布时间】:2016-05-03 03:08:21
【问题描述】:

我正在尝试获取复选框的值,并尝试了以下操作:

var closedIssue = $('#closed-' + rowCounter).val();

但它总是返回'on'

这里是复选框

<input type="checkbox" name="closed-' + rowCounter + '" id="closed-' + rowCounter + '" />

我做错了什么?

【问题讨论】:

    标签: jquery


    【解决方案1】:

    改为使用.prop() method 获取checked property。它将返回一个布尔值。

    var closedIssue = $('#closed-' + rowCounter).prop('checked');
    

    或纯 JavaScript:

    var closedIssue = document.getElementById('closed-' + rowCounter).checked;
    

    【讨论】:

      【解决方案2】:
      var returnCheck = $('#closed-' + rowCounter).is(':checked');
      

      将返回复选框的当前状态。

      【讨论】:

        猜你喜欢
        • 2018-07-05
        • 2013-10-29
        • 2012-12-26
        • 1970-01-01
        • 2021-08-24
        • 1970-01-01
        • 2019-03-13
        相关资源
        最近更新 更多