亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問JavaScript表單提交-確認或取消提交對話框

請問JavaScript表單提交-確認或取消提交對話框

肥皂起泡泡 2019-10-21 16:12:49
JavaScript表單提交-確認或取消提交對話框對于具有詢問字段是否正確填寫的警報的簡單表單,我需要一個這樣做的函數:使用兩個選項單擊按鈕時顯示一個警告框:如果單擊“確定”,則提交表單。如果單擊“取消”,則“警報”框將關閉,并可對窗體進行調整和重新提交。我認為JavaScript確認會起作用,但我似乎不知道怎么做。我現在的代碼是:function show_alert() {  alert("xxxxxx");}<form>  <input type="image" src="xxx" border="0" name="submit" onclick="show_alert();" alt="PayPal - The safer, easier way to pay online!" value="Submit"></form>
查看完整描述

3 回答

?
米脂

TA貢獻1836條經驗 獲得超3個贊

簡單內聯JavaScript確認就夠了:

<form onsubmit="return confirm('Do you really want to submit the form?');">

不需要外部功能除非你在做驗證,你可以這樣做:

<script>function validate(form) {

    // validation code here ...


    if(!valid) {
        alert('Please correct the errors in the form!');
        return false;
    }
    else {
        return confirm('Do you really want to submit the form?');
    }}</script><form onsubmit="return validate(this);">



查看完整回答
反對 回復 2019-10-22
?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

function show_alert() {   if(confirm("Do you really want to do this?"))     document.forms[0].submit();   else     return false;}

查看完整回答
反對 回復 2019-10-22
?
莫回無

TA貢獻1865條經驗 獲得超7個贊

好的,只需將代碼更改為如下內容:

<script>function submit() {
   return confirm('Do you really want to submit the form?');}</script><form onsubmit="return submit(this);">
   <input type="image" src="xxx" border="0" name="submit" onclick="show_alert();"
      alt="PayPal - The safer, easier way to pay online!" value="Submit"></form>

這也是運行中的代碼,只是我更容易看到它是如何工作的,只需運行下面的代碼就可以看到結果:

function submitForm() {
  return confirm('Do you really want to submit the form?');}
<form onsubmit="return submitForm(this);">
  <input type="text" border="0" name="submit" />
  <button value="submit">submit</button></form>



查看完整回答
反對 回復 2019-10-22
  • 3 回答
  • 0 關注
  • 382 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號