JIVery DIV中的每个输入(有一个表)

LmC*_*LmC 4 html javascript foreach jquery input

我目前正试图从DIV获取所有输入元素.

$("[required]").each(function() {

});
Run Code Online (Sandbox Code Playgroud)

我有这个代码,它返回带有required属性的每个元素.

我知道在功能中each()我可以使用每个项目,如:

$(this)
Run Code Online (Sandbox Code Playgroud)

所以我得到下面显示的div ID,并尝试从中获取所有输入:

var id = $(this).attr('id');
console.log("### " + id);
console.log($("#" + id + " > :input").length);
Run Code Online (Sandbox Code Playgroud)

当我在该DIV中有4个put元素时,返回0(也是div中的表).

我理想的做法是为div中的每个输入元素打印其ID.

更新

<div id="contactAddress" required="true">

 <td>Addres line 1:</td>
 <td colspan="2">
 <input type="text"/>
 </td>
 <td>Addres line 2:</td>
 <td colspan="2">
 <input type="text" />
 </td>
 </tr>
</div>

console.log($(this).html());
Run Code Online (Sandbox Code Playgroud)

显示不高,但如果我添加任何超出下面或类似...

 <div id="contactAddress" required="true">
 <input type="text" />
Run Code Online (Sandbox Code Playgroud)

并运行 console.log($(this).html());它显示它不放表?

任何想法我使用Jquery Mobile

Und*_*ned 7

下面将找到div元素内的所有输入.然后它将留下该元素的id的日志.

$("div > input").each(function() {
  console.log( $(this).attr("id") );
});
Run Code Online (Sandbox Code Playgroud)

如果你需要包含你可以使用的输入的div id .parent()

$("input").each(function() {
  console.log( $(this).parent().attr("id") );
});
Run Code Online (Sandbox Code Playgroud)