【问题标题】:jquery - Check if input text field is filled, save to varjquery - 检查输入文本字段是否已填充,保存到 var
【发布时间】:2014-03-01 18:43:32
【问题描述】:

我有一个带有单选按钮和文本字段的表单。

我可以将选中的单选按钮的数量存储到这样的变量中:

var $answeredRadiobuttons = $questions.find("input:radio:checked").length;

如何存储包含文本的文本字段的数量?

var $answeredTextfields = $questions.find("input:text").length;

【问题讨论】:

    标签: javascript jquery input string-length


    【解决方案1】:

    使用:

    var $answeredTextfields = $("input").filter(function() {
      return $(this).val() != "";
    }).length;
    

    Working Demo

    【讨论】:

      【解决方案2】:

      试试:

      var $answeredTextfields = $questions.find("input:text").filter(function(){
          return this.value !== "";
      }).length;
      

      【讨论】:

        猜你喜欢
        • 2018-01-29
        • 1970-01-01
        • 2017-06-01
        • 1970-01-01
        • 2023-04-10
        • 1970-01-01
        • 2013-06-18
        • 1970-01-01
        • 2021-02-27
        相关资源
        最近更新 更多