我有这个:
<a style="display: inline-block; width: 100px; font-weight: bold;"
href="javascript:submit()">Search</a>
而不是带提交的按钮,但是当您单击时没有任何反应..
怎么做呢?
答案 0 :(得分:4)
您需要document.yourFormNameHere.submit();
而不仅仅是submit()
答案 1 :(得分:1)
<form id='demoForm'><br>
Demo field<input type='text' name='demoItem' /><br>
</form>
//place this link anywhere in html
<a style="display: inline-block; width: 100px; font-weight: bold;"
href="submitForm()">Search</a>
///java script
function submitForm()
{
document.getElementById('demoForm').submit();
}
答案 2 :(得分:0)
您必须定义要提交的表单..
所以给表单一个id并使用它来定位这样的表单
<form id="someid">
...
<a style="display: inline-block; width: 100px; font-weight: bold;" href="javascript:document.getElementById('someid').submit()" >Search </a>
答案 3 :(得分:0)
你有javascript:submit(),但是要提交什么?尝试以下方面:
href="javascript:document.getElementById('formId').submit();"
或者甚至更好,尝试给你一个id,然后将样式和javascript适当地移动到单独的文件中。这将使您的标记保持清洁并且更易于管理。
/* in some sort of external css that is included */
#formSubmissionLink {
display: inline-block;
font-weight: bold;
width: 100px;
}
/* in some sort of external JS that is included at the end of the html*/
(function () {
document.getElementById("formSubmissionLink").onclick = function () {
document.getElementById("formId").submit();
return false;
};
})();
然后你的html将是: &lt; a id =“formSubmissionLink”href =“#”&gt;搜索&lt; / a&gt;