javascript實現刪除前彈出確認框

來源:互聯網
上載者:User

   刪除確認對話方塊的JS代碼,有好幾種寫法,有簡單的,有相容好的,下面分別說幾種方法,可根據自己需要選用

  需求:使用者點擊刪除按鈕時,彈出一個確定框,如果使用者點擊“確定”執行刪除操作,否則不執行

  JS代碼

  ?

1 2 3 4 5 6 7 8 function del() { var msg = "您真的確定要刪除嗎?nn請確認!"; if (confirm(msg)==true){ return true; }else{ return false; } }

  html代碼

  ?

1 <a href="" onclick="javascript:return del();">刪除</a>

  方法二:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>確認是否刪除</title> <script type="text/javascript"> function del(){ if(!confirm("確認要刪除?")){ window.event.returnValue = false; } } </script> </head> <body> <a href="http://www.baidu.com" onclick="return del()">刪除</a> </body> </html>

  方法三:

  ?

1 <a href="javascript:if(confirm('確實要刪除嗎?'))location='jb51.php?id='">刪除</a>

  方法四:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 <script type="text/javascript" language="javascript"> <!-- function confirmAct() { if(confirm('確定要執行此操作嗎?')) { return true; } return false; } //--> </script>   <a href="operate.php?mod=user&act=delete&id=564" onclick="return confirmAct();">執行操作</a>

  以上所述就是本文的全部內容了,希望大家能夠喜歡。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.