我有一个这样的表格:
<form id = "membershipInfo" method = "post" action = "Default.aspx" onsubmit = "dialogSubmitForm()" \>
<input type = "text" id = "changeStoreDialogText" name = "ChangeLocation" value="" />
<input type = "submit" id = "DialogSubmit" value = ""/>
</form>
有些时候,我希望提交会导致页面加载,而其他时候我不希望它。这是dialogSubmitForm
:
function dialogSubmitForm() {
//Checks to see how to submit
if (placeHolderVisibility) {
//Checks to ensure that the correct information was entered
if (!isNaN($(codeChange).val()) && ($(codeChange).val()).length == 5) {
//Submit at page load
} else {
//code
//Do not submit to pageload
return false;
}
}
else //Do submit through javascript
{
//Code
//Do not submit to pageload
return false;
}
}
我认为返回false不会导致页面加载,但显然确实如此。如何使用提交按钮阻止页面加载?
答案 0 :(得分:2)
你可以尝试
onsubmit = "return dialogSubmitForm()" \>
如果在dialogSubmitForm()函数中返回false,这将阻止提交。
答案 1 :(得分:0)
<input type="submit" id="DialogSubmit" value="Submit!" onclick="return false;"/>
这会阻止页面加载
所以在你的情况下,它会更像是这样:
<input type="submit" id="DialogSubmit" value="Submit!" onclick="return dialogSubmitForm();"/>