【发布时间】:2011-01-21 00:34:49
【问题描述】:
我知道,使用 Javascript,我可以使用以下方式告诉表单提交:
document.forms[0].submit()
但是,如果页面上有多个表单,可以按任意顺序排列,我将如何定位此表单中的提交链接:
<form action="/services/auth/" method="post">
<div id="auth-allow-container" class="button-container">
<a class="Butt" id="auth-allow" type="submit" href="#"><span>SUBMIT</span></a>
<a class="Butt CancelButt" id="auth-disallow" href="#home"><span>CANCEL</span></a>
</div>
</form>
..这样就好像用户点击了提交一样?
【问题讨论】:
-
您的 FORM 元素不包含任何表单域。此外,您将锚上的 type 属性设置为“提交”。但是锚的 type 属性有不同的功能:w3.org/TR/html401/struct/links.html#adef-type-A 你应该使用这个:
<input type=submit> -
有几个表单字段,我只是错过了它们。您可能对 type 属性是正确的 - 但是,我无法控制 html。 (顺便说一下,这是flickr的标准验证码)
-
那么,你使用的是 JS 库吗?
-
不,没有 js 库。我正在为 iPhone UIWebView 使用 stringByEvaluatingJavaScriptFromString 方法,所以我不能使用库 iphoneincubator.com/blog/windows-views/…
-
呵呵,那个类名是“Butt”。
标签: javascript dom forms