原创 自己封装的js alert 和confirm 利用jquery dialog

下面是封装的代码:

  1. function alert(message){
  2.     if ($("#dialogalert").length == 0) {
  3.         $("body").append('
');
  •         $("#dialogalert").dialog({
  •             autoOpen: false,
  •             title: '消息框',
  •             modal: true,
  •             resizable:false,
  •             overlay: {
  •                 opacity: 0.5,
  •                 background: "black"
  •             },
  •             buttons: {
  •                 "确定"function(){
  •                     $(this).dialog("close");
  •                 }
  •             }
  •         });
  •     }
  •     
  •     $("#dialogalert").html(message);
  •     $("#dialogalert").dialog("open");
  • }
  • function confirm(message, callback){
  •     if ($("#dialogconfirm").length == 0) {
  •         $("body").append('
  • ');
  •         $("#dialogconfirm").dialog({
  •             autoOpen: false,
  •             title: '消息框',
  •             modal: true,
  •             resizable:false,
  •             overlay: {
  •                 opacity: 0.5,
  •                 background: "black"
  •             },
  •             buttons: {
  •                 "确定"function(){
  •                     callback();
  •                     $(this).dialog("close");
  •                 },
  •                 "取消"function(){
  •                     $(this).dialog("close");
  •                 }
  •             }
  •         });
  •     }
  •     $("#dialogconfirm").html(message);
  •     $("#dialogconfirm").dialog("open");    
  • }
  • 把这个文件存为util.js

    使用方法

    先导入css和javascript库(根据自己实际情况)


    需要拖拽移动等功能,请添加相应的库


    在你需要弹出消息对话框或者选择对话框时使用下面方法:

    1. alert("发表成功!");
    2. confirm("确认要删除所选?此操作不可恢复!"function(){
    3.             $.ajax({
    4.                 url: actionurl,
    5.                 data: {
    6.                     date: new Date().getTime(),
    7.                     action: "delete",
    8.                     ids: getSelectIDs()
    9.                 },
    10.                 success: function(data){
    11.                     if (data == "1") {
    12.                         alert("删除成功!");
    13.                         getAll();
    14.                         $("#selectalllabel").html("全部选择");
    15.                         $("#selectall").removeAttr("checked");
    16.                     }
    17.                     else {
    18.                         alert("删除失败!");
    19.                     }
    20.                     idstr = "";
    21.                 }
    22.             });
    23.         });



    学了一段时间jquery,这是我第一个原创文章,欢迎大家指教
    有什么问题,大家一顶告诉我 qq:281924282 msn:[email protected]







    你可能感兴趣的:(JAVA,技术文章)