Javascript 如何使用jquery查找表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11853543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find a form using jquery
提问by Arcturus
I have multiple forms on a page. How do I find a form by its name? I think in pure javascript it is something like document.forms['FormName'] .
我在一个页面上有多个表单。如何按名称查找表单?我认为在纯 javascript 中它类似于 document.forms['FormName'] 。
I want to do a form.submit. But I want to be able to select a form by its name.
我想做一个form.submit。但我希望能够按名称选择表单。
回答by Blazemonger
No jQuery required -- just use the built-in JavaScript submit()
method:
不需要 jQuery —— 只需使用内置的 JavaScriptsubmit()
方法:
document.forms['FormName'].submit();
回答by Michael Haren
You can add an attribute selectorto get the form you want:
你可以添加一个属性选择器来获得你想要的形式:
$('form[name="foo"]')...
回答by Zack Tanner
Give your form an ID or class attribute. In the case of an ID:
给你的表单一个 ID 或 class 属性。在 ID 的情况下:
$("#formName").function()
$("#formName").function()
Your HTML:
你的 HTML:
<form id="formName">
<form id="formName">
Where function is what you plan on doing...
功能是你打算做什么......