如何使用$ .each迭代所有输入隐藏值

mmu*_*lva 6 jquery

我想对每个隐藏的输入值做一些事情,所以我使用jQuery编写了以下javascript .

$.each($("input[type='hidden']"), function (index, value) {
    alert(value.val());
});
Run Code Online (Sandbox Code Playgroud)

但我得到他执行错误: value.val is not a function.

我究竟做错了什么?

C. *_* E. 12

这可行:

$("input[type=hidden]").each(function() {
     $(this).val() //do something with
});
Run Code Online (Sandbox Code Playgroud)


Dim*_*try 9

迭代函数中的值是Node,而不是jQuery对象.

你仍然需要去: $(value).val();

请参阅此处的最后一个示例:http://api.jquery.com/each/