javascript - JQuery 忽略隐藏 div 中的元素值

标签 javascript jquery html

如何忽略隐藏 div 中的元素?我有一个包含可见元素和隐藏在 div 中的一些元素的表单...

<form id="my-form">
  <input name="split_values[]" class="split">
  <input name="split_values[]" class="split">
  <input name="split_values[]" class="split">
  <div class="hidden-div">
    <input name="split_values[]" class="split">
  </div>
</form>

我正在遍历验证元素......

$('#my-form *').filter(':input').each(function(){ 
  // my validation here
});

但我想忽略隐藏 div 中的任何值。所以我只想查看隐藏 div 中前 3 个元素的验证,而不是第四个元素的验证。由于元素是动态生成的,我不可能给它们提供 id。

提前致谢。

最佳答案

您可以使用:visible伪选择器过滤掉隐藏的输入字段:

$('#my-form *').filter(':input:visible').each(function() {
   // my validation here
});

关于javascript - JQuery 忽略隐藏 div 中的元素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44592237/

相关文章:

javascript - jQuery 冒号选择器

jquery - 不从引导模式中删除

html - 文本比另一侧更倾向于一侧

ios - flex-item 中的图像在 Safari、iOS 和 Firefox 中重写 "max-width: none"

html - 小 1px,2px 间距的问题,同时使用边框半径(在所有浏览器中)

javascript - Ember : change attribute of nullable relationship

javascript - 如何向每个嵌套 div 添加相同的顺序类?

javascript - Webgl 动画纹理性能与 canvas drawImage 性能

jquery - 在wordpress中使用ajax动态加载帖子

javascript - e.preventDefault(); undefined 不是函数