2 回答

TA貢獻1806條經驗 獲得超8個贊
首先,要將輸入更改為按鈕,請使用以下命令(注意: 元素<button>
而不是<input>
):
<button type="submit" name="submit">Submit</button>
然后要提交您的表格,您可以執行以下任一操作:
正如您已經做的那樣,使用按鈕中的 onclick 來調用 js 函數,例如
<button type="submit" name="submit" onclick="submitData();">Submit</button>
或onsubmit
提交表單的標準方法是在元素中使用form
并僅使用 javascript 函數進行驗證,如下所示:[...您的表單字段在這里...]
<button type="submit" name="submit">Submit</button>
如果您使用,那么如果一切都可以提交,那么onsubmit
您的驗證函數應該返回,否則表單將阻止提交發生。表格本身將完成剩下的工作!true
false
function submitData() {
// your validation checks here...
if (!(input === "") && (!(option1.checked === false) || !(option2.checked === false))) {
return true; // no errors so return true to the form so it knows its ok to continue.
}
// if there were errors, return false so that the form knows not to submit
return false;
}

TA貢獻1804條經驗 獲得超7個贊
還有其他方法可以解決此問題,但這里有一個:
您可以將按鈕類型保留為“提交”,但附加 CSS:
CSS(只是一個例子......你可以使用任何其他CSS):
.button{ padding:9px; font-size: 16px; background:#00912a; border:1px solid #037223; color:#fff !important;}
.button:hover{ background:#fff; border:1px solid #037223; color:#037223 !important;}
代碼:
<input type="submit" class="button" value="Submit" name="submit" onclick="submitData();" ><br/>
- 2 回答
- 0 關注
- 179 瀏覽
添加回答
舉報