文本链接不会使用名称在Safari中通过JavaScript提交表单 [英] Text link won't submit form by JavaScript in Safari using name
问题描述
I'm using Safari 5.0.3 I have a form in my html:
我使用Safari 5.0.3我在html中有一个表单: style =margin-top:24px;>
< h4 style =float:left; margin-top:-1px;>搜寻< / h4>
& nbsp; < input type =textname =keywordsid =keywords>< / input> &安培; NBSP; < a href =#onClick =document.forms [0] .submit(); return false> Go>< / a>
< / form>
<form name="searchForm" style="margin-top:24px;">
<h4 style="float:left;margin-top:-1px;">Search</h4>
<input type="text" name="keywords" id="keywords"></input> <a href="#" onClick="document.forms[0].submit(); return false">Go ></a>
</form>
这可以正常工作:
This works fine:
a href="#" onClick="document.forms[0].submit(); return false"
但这没有任何作用:
but this does nothing:
a href="#" onClick="document.forms['searchForm'].submit(); return false"
我需要使用后者,因为页面模板是动态的,有时在这个页面之前会有一个页面中的表单。
I need to use the latter, because the page template is dynamic, and sometimes there will be a form in the page before this one.
推荐答案
使用:document.getElementById ('searchForm')。submit()。
Use: document.getElementById('searchForm').submit() instead.
这篇关于文本链接不会使用名称在Safari中通过JavaScript提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!