[英]How to get all form attributes present in a div?
I want attributes like name, Id of forms present in a div 我想要div中存在的名称,表格ID之类的属性
<div id="searchForms">
<form id="form1" name="form1">
</form>
<form id="form2" name="form2">
</form>
</div>
<form id="form3" name="form3">
</form>
So what presently I am doing 所以我现在在做什么
$('form').each(function () {
console.log($(this).attr('id'));
console.log($(this).attr('name'));
});
But the problem is that it is giving me the name and id's of all the three forms. 但是问题在于,这给了我这三种形式的名称和ID。 I want the name and id's of all the forms present in the div whose id is id="searchForms"
. 我想要div中ID为id="searchForms"
的所有表单的名称和ID。
You need Descendant Selector (“ancestor descendant”) , use the id of parent div that is searchForms
as ancestor
and form as descendant
您需要Descendant Selector(“祖先后代”) ,使用父div的id(即searchForms
作为ancestor
,form作为descendant
$('#searchForms form').each(function () {
console.log($(this).attr('id'));
console.log($(this).attr('name'));
});
Description: Selects all elements that are descendants of a given ancestor. 描述:选择作为给定祖先的后代的所有元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.