如何获取所有未隐藏类型的输入的值



我想清除所有输入的值,但隐藏的输入类型除外,该类型包含我想在服务器上提交的一些值。

选择表单

中的所有表单字段但忽略选择中的隐藏字段的最佳方法是什么?

您可以尝试像这样选择:

$(":input:not([type=hidden])")

您可以在此处参考更多内容

使用 :

hidden 和 :not(( 选择器,例如,

$('input:not(:hidden)').val('');

$(function() {
  $('input:not(:hidden)').val('');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" value="one" /><br/>
<input type="text" value="two" /><br/>
<input type="hidden" value="one hidden" /><br/>
<input type="text" value="three" /><br/>

选择所有未隐藏的输入字段。

jQuery('input[type!=hidden]').val('');

你试过吗$('input[type!=hidden]'(?

正如你提到的表单输入:

  $('form input:not([type=hidden])')

这个jQuery选择器对我有用。我正在尝试获取表单内所有字段的列表,该表单是输入元素,不是隐藏输入,也不是按钮

let formFields = jQuery('form.my-form').find(':input:not(:hidden):not(:button)');

最新更新