jQuery查找父表单 [英] jQuery find parent form

查看:85
本文介绍了jQuery查找父表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个html

<ul>
    <li><form action="#" name="formName"></li>
    <li><input type="text" name="someName" /></li>
    <li><input type="text" name="someOtherName" /></li>
    <li><input type="submit" name="submitButton" value="send"></li>
    <li></form></li>
</ul>

我该如何选择input[name="submitButton"]所属于的形式? (当我单击提交"按钮时,我想选择表格并在其中添加一些字段)

How can i select the form that the input[name="submitButton"] is part of ? (when i click on the submit button i want to select the form and append some fields in it)

推荐答案

我建议使用 closest ,它会选择最匹配的父元素:

I would suggest using closest, which selects the closest matching parent element:

$('input[name="submitButton"]').closest("form");

我不会按名称过滤,而是这样做:

Instead of filtering by the name, I would do this:

$('input[type=submit]').closest("form");

这篇关于jQuery查找父表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆