刪除確認(rèn)對(duì)話框的JS代碼,有好幾種寫法,有簡(jiǎn)單的,有兼容好的,下面分別說幾種方法,可根據(jù)自己需要選用
需求:用戶點(diǎn)擊刪除按鈕時(shí),彈出一個(gè)確定框,如果用戶點(diǎn)擊“確定”執(zhí)行刪除操作,否則不執(zhí)行
JS代碼
- function del() {
- var msg = "您真的確定要?jiǎng)h除嗎?/n/n請(qǐng)確認(rèn)!";
- if (confirm(msg)==true){
- return true;
- }else{
- return false;
- }
- }
html代碼
- <a href="" onclick="javascript:return del();">刪除</a>
方法二:
- <!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>確認(rèn)是否刪除</title>
- <script type="text/javascript">
- function del(){
- if(!confirm("確認(rèn)要?jiǎng)h除?")){
- window.event.returnValue = false;
- }
- }
- </script>
- </head>
- <body>
- <a href="http://www.baidu.com" onclick="return del()">刪除</a>
- </body>
- </html>
方法三:
- <a href="javascript:if(confirm('確實(shí)要?jiǎng)h除嗎?'))location='jb51.php?id='">刪除</a>
方法四:
- <script type="text/javascript" language="javascript">
- <!--
- function confirmAct()
- {
- if(confirm('確定要執(zhí)行此操作嗎?'))
- {
- return true;
- }
- return false;
- }
- //-->
- </script>
- <a href="operate.php?mod=user&act=delete&id=564" onclick="return confirmAct();">執(zhí)行操作</a>
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
新聞熱點(diǎn)
疑難解答
圖片精選