简体   繁体   English

jQuery-检查输入文本字段是否已填充,保存到var

[英]jquery - Check if input text field is filled, save to var

I have a form with radiobuttons and textfields. 我有一个带有单选按钮和文本字段的表单。

I can store number of checked radiobuttons into a variable like this: 我可以将选中的单选按钮的数量存储到这样的变量中:

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

How can I store number of textfields that has text within them? 如何存储其中包含文本的多个文本字段?

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

use: 采用:

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

Working Demo 工作演示

Try: 尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM