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:
<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="doc开发者_C百科ument.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.
Use: document.getElementById('searchForm').submit() instead.
Try this out:
<a href="#" onClick="document.searchForm.submit(); return false;">
If that doesn't work, Macy Abbey has a great idea of adding an id to the form and referencing it by that.
精彩评论