我有這樣的:提交表單與正常鏈接,不會工作
<a style="display: inline-block; width: 100px; font-weight: bold;"
href="javascript:submit()">Search</a>
作爲,而不是用一個提交按鈕,但是當你點擊沒有任何反應..
如何才能做到這一點?
我有這樣的:提交表單與正常鏈接,不會工作
<a style="display: inline-block; width: 100px; font-weight: bold;"
href="javascript:submit()">Search</a>
作爲,而不是用一個提交按鈕,但是當你點擊沒有任何反應..
如何才能做到這一點?
你需要document.yourFormNameHere.submit();
不僅僅是submit()
您必須定義要提交的表單..
這樣就給形式的ID,並用它來定位的形式這樣
<form id="someid">
...
<a style="display: inline-block; width: 100px; font-weight: bold;" href="javascript:document.getElementById('someid').submit()" >Search </a>
你有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是: <一個ID = 「formSubmissionLink的」 href = 「#」>搜索</A>
<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();
}
什麼是您的'提交()'函數的樣子?如果你認爲這個,它不是表單的提交功能。你必須明確地引用該表格,例如'document.formname.submit()'。 – 2010-09-26 16:19:39
爲什麼不使用'' – BCS 2010-09-26 16:19:55