jquery - 获取位于特定类中的所有文本字段值

标签 jquery

我想获取位于单个类名中的所有字段,例如我的代码。

<div class="test">
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />
</div>

<div class="test">
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />
 <input type="text" class="text-field" />
</div>

我想要获取每个循环,其中它返回位于此类中的文本字段值。有什么建议吗?

最佳答案

试试这个:

$(".test .text-field")

编辑:

要获取值,请尝试以下操作:

$(".test .text-field").each(function() {
    alert($(this).val());
});

关于jquery - 获取位于特定类中的所有文本字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6758301/

相关文章:

jquery - 如何覆盖 jQuery touchSwipe 处理程序?

javascript - 如何使用 jQuery 将 JavaScript 代码添加到现有的 iFrame 中?

jquery - 为什么程序无法读取文件 json?

jquery动画: change span color not working

javascript - 不规则形状的碰撞检测

jquery - 动画关闭切换滑动面板?

jquery - 如果我们将同一个 div 绑定(bind)两次,一次在 js 文件中,一次作为内联脚本,会发生什么

jquery - 谷歌地图与 IE8 的问题

javascript - 获取数据绑定(bind)的元素(使用 KnockoutJS)

javascript 显示-隐藏特定时间的元素