2009-09-29 98 views

回答

1

在您的FORM元素中,您需要用JavaScript函數覆蓋onsubmit事件並返回true。

<script type="text/javascript"> 
    function onFormSubmit() 
    { 
     document.myform.someInput.value = ""; 
     return true; // allow form submission to continue 
    } 
</script> 
<form name="myform" method="post" action="someaction.php" onsubmit="return onFormSubmit()"> 
<!-- form elements --> 
</form> 
+0

嗯哦......不會有這樣的服務器端處理這個帖子沒有看到任何的效果相應的表單域? – mjv 2009-09-29 05:54:37

+0

可以。我必須承認,我從來沒有這樣做過。我希望POST數據在繼續之前被取整。 – 2009-09-29 22:06:12

1

如果用戶按下表單上的submitbutton,數據將被提交給表單的action屬性中給出的腳本。這意味着用戶從網站導航。刷新後(假設表單的動作與源相同),輸入字段將爲空(因爲它首先是空的)。

如果您通過JavaScript提交數據並且沒有重新加載頁面,請確保在提交數據後執行Nick的代碼。

希望這是明確的(雖然我懷疑這一點,我的英語很糟糕有時)..

0

功能testSubmit(){ VAR X = document.forms [ 「myForm會」] [」輸入1" ]; var y = document.forms [「myForm」] [「input2」]; if(x.value ===「」) {alert}('plz fill !!'); 返回false; } if(y.value ===「」) { alert('plz fill the !!'); 返回false; } return true; ()) } function submitForm() if(testSubmit()) { document.forms [「myForm」]。submit(); //第一次提交 document.forms [「myForm」]。reset(); //然後重置表單值 }}

First Name: <input type="text" name="input1"/> 
    <br/> 
    Last Name: <input type="text" name="input2"/> 
    <br/> 
    <input type="button" value="Submit" onclick="submitForm()"/> 
</form>