使用artDialog做确认取消操作,本教程以删除操作为例,点击按钮,弹出确认取消对话框,点击确认按钮,执行删除操作,点击取消按钮则取消本次操作。

要实现这个操作有2种方法,使用artDialog的iframe扩展来做和不使用iframe扩展。如果使用iframe,则要在页面中载入

 
  
  1. <script src="artDialog/plugins/iframeTools.source.js"></script>  

index.html中的代码:

 
  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  5. <title>artDialog对话框在PHP下的简单应用-artDialog确认取消对话框的制作代码</title> 
  6. <style> 
  7. body { 
  8.     font-size: 12px; 
  9. </style> 
  10. <script src="jiaocheng.js"></script>  
  11. <script src="artDialog/artDialog.source.js?skin=default"></script>  
  12. <script src="artDialog/plugins/iframeTools.source.js"></script> 
  13. </head> 
  14.  
  15. <body> 
  16. <a href="#" onclick="DelSel()">弹出确认对话框1</a><br/> 
  17. <a href="#" onclick="DelSel2()">弹出确认对话框2</a> 
  18. </body> 
  19. </html> 

index.php代码:

 
  
  1. <?php 
  2. $text=$_GET['text']; 
  3. if ($text=='test'
  4. echo 'chenggong'
  5. else 
  6. echo 'shibai'
  7. ?> 

jiaocheng.js中的代码:

 
  
  1. //使用iframe扩展
  2. function DelSel(){ 
  3.    art.dialog.confirm('你确定要删除这些文件吗?'function () { 
  4.    this.close(); 
  5.    $.ajax({ 
  6.     type: 'get'
  7.     url: 'index.php?text=test'
  8.     contentType: 'text/html;charset=utf-8'
  9.     success: function(data, status) { 
  10.       switch (data) {  
  11.       case 'chenggong'
  12.         art.dialog.tips('成功删除'); 
  13.         break
  14.       default
  15.         art.dialog.tips('删除失败'); 
  16.       } 
  17.       return false
  18.     } 
  19.   }); 
  20.   return false
  21. }, function () { 
  22.     art.dialog.tips('你取消了操作'); 
  23. });  
  24. //不使用iframe扩展方法
  25. function DelSel2(){ 
  26.    art.dialog({ 
  27.     id:'del'
  28.     content: '你确定要删除这些文件吗?'
  29.     ok: function () { 
  30.     $.ajax({ 
  31.     type: 'get'
  32.     url: 'index.php?text=test'
  33.     contentType: 'text/html;charset=utf-8'
  34.     success: function(data, status) { 
  35.       switch (data) {  
  36.       case 'chenggong'
  37.         parent.art.dialog.list['del'].close(); 
  38.         art.dialog({ 
  39.         id: 'testID1'
  40.         content: '删除成功' 
  41.         }); 
  42.         art.dialog({id: 'testID1'}).time(1); 
  43.         break
  44.       default
  45.         parent.art.dialog.list['del'].close(); 
  46.         art.dialog({ 
  47.         id: 'testID1'
  48.         content: '删除失败' 
  49.         }); 
  50.         art.dialog({id: 'testID1'}).time(1); 
  51.       } 
  52.       return false
  53.     } 
  54.   }); 
  55.         return false
  56.     }, 
  57.     cancelVal: '取消'
  58.     cancel: true //为true等价于function(){} 
  59. }); 

具体可以下载附件中的例子来学习。

附件下载:http://www.sitejs.cn/download/201304/file/16574.rar

artDialog4.1.7下载地址:http://www.sitejs.cn/sitejs-16571-1.html

更多PHP教程请访问JS代码

本文原地址:http://www.sitejs.cn/sitejs-16574-1.html