HTML:
<div id="panel">
<table>
<tr>
<td><input id="Search_NazovProjektu" type="text" value="" /></td>
</tr>
<tr>
<td><input id="Search_Popis" type="text" value="" /></td>
</tr>
</table>
</div>
我需要选择特定div中的所有输入。
这不起作用:
var i = $("#panel > :input");
发布于 2010-12-22 00:51:50
“find”方法可用于获取已缓存的容器的所有子输入,以避免再次查找(而“child”方法将仅获取直接的子项)。例如:
var panel= $("#panel");
var inputs = panel.find("input");
发布于 2013-08-20 21:09:35
如果你使用像Ruby on Rails或Spring MVC这样的框架,你可能需要使用带有方括号或其他字符的div,这是不允许的,你可以使用document.getElementById
,如果你有多个相同类型的输入,这个解决方案仍然有效。
var div = document.getElementById(divID);
$(div).find('input:text, input:password, input:file, select, textarea')
.each(function() {
$(this).val('');
});
$(div).find('input:radio, input:checkbox').each(function() {
$(this).removeAttr('checked');
$(this).removeAttr('selected');
});
这个例子展示了如何清除输入,对于你来说,你需要修改它。
发布于 2015-12-23 14:21:40
以下是我的方法:
您可以在其他事件中使用它。
var id;
$("#panel :input").each(function(e){
id = this.id;
// show id
console.log("#"+id);
// show input value
console.log(this.value);
// disable input if you want
//$("#"+id).prop('disabled', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="panel">
<table>
<tr>
<td><input id="Search_NazovProjektu" type="text" value="Naz Val" /></td>
</tr>
<tr>
<td><input id="Search_Popis" type="text" value="Po Val" /></td>
</tr>
</table>
</div>
https://stackoverflow.com/questions/2402707
复制相似问题