Title1

Title2

Title3

12-1 sweet-alert

一、樣板

  1. 引入
    
      <link rel="stylesheet" href="<{xoAppUrl modules/tadtools/sweet-alert/sweet-alert.css}>" type="text/css" />
      <script src="<{xoAppUrl modules/tadtools/sweet-alert/sweet-alert.js}>" type="text/javascript"></script>

     

  2. 調用插件
    刪除
      
      <script type="text/javascript">
        $(function() {      
          //每行的删除操作注册脚本事件
          $(".btnDel").bind("click", function(){
            var vbtnDel=$(this);//得到点击的按钮对象
            var vTr=vbtnDel.parents("tr");//得到父tr对象;
            var sn=vTr.attr("sn");//取得 sn       
            var title=vTr.find(".title").html();//取得 title
            //警告視窗
            swal({
              title: '<{$smarty.const._TAD_DEL_CONFIRM_TITLE}>',
              text: title,
              type: 'warning',
              showCancelButton: 1,
              confirmButtonColor: '#DD6B55',
              confirmButtonText: '<{$smarty.const._TAD_DEL_CONFIRM_BTN}>',
              closeOnConfirm: false ,
              allowOutsideClick: true
            },
            function(){
              //確定,執行
              $.post('<{$SCRIPT_NAME}>', {op:"opDelete",sn:sn}, function(msg){
              	console.log(msg);
                if(msg==1){              
                  vTr.remove();//刪除
                  swal("刪除完成!", title, "success");
                }else{
                  swal("刪除失敗!", title, "error");
                }
              });
    
            });              
          });
          //给删除按钮注册js脚本
        });
      </script>

    啟用
     

    
      <{* 啟用/停用 *}> 
      <script type="text/javascript">
        $(function() {      
          //每行的啟用/停用操作注册脚本事件
          $(".btnEnable").bind("click", function(){
            var btnEnable=$(this);//得到点击的按钮对象     
            var enable=btnEnable.attr("enable");//取得 enable
    
            var vTr=btnEnable.parents("tr");//得到父tr对象;
            var sn=vTr.attr("sn");//取得 sn       
            var title=vTr.find(".title").html();//取得 title 
    
            if(enable ==1){
              confirmTitle="確定要停用";
              vEnable="0";
              htmlEnable="<img src='<{$xoops_url}>/modules/ugm_tools2/images/off.png' />";
            }else{
              confirmTitle="確定要啟用";
              vEnable="1";
              htmlEnable="<img src='<{$xoops_url}>/modules/ugm_tools2/images/on.png' />";
            }
            //警告視窗
            swal({
              title: confirmTitle,
              text: title,
              type: 'warning',
              showCancelButton: 1,
              confirmButtonColor: '#DD6B55',
              confirmButtonText: confirmTitle,
              closeOnConfirm: false ,
              allowOutsideClick: true
            },
            function(){
              //確定,執行
              $.post('<{$SCRIPT_NAME}>', {op:"opUpdateEnable",sn:sn,enable:vEnable}, function(msg){
                if(msg ==1){
                  btnEnable.attr("enable",vEnable);//取得 enable
                  btnEnable.html(htmlEnable);
                  swal("設定完成!", title, "success");
                }else{
                  swal("設定失敗!", title, "error");
                }
                
              });//          
              
            });              
          });
          //给啟用/停用按钮注册js脚本
        });
      </script>

     

  3. 檢查
    
            //檢查廠商編號是否輸入
            var vendor =  $('#vendor').val();//取得廠商流水號
            if(!vendor)
            {
              //警告視窗
              swal({
                title: '請輸入廠商編號!',
                text: "您尚未輸入廠商!",
                type: 'info',
                showCancelButton: 0,
                //confirmButtonColor: '#DD6B55',
                confirmButtonText: '確定',
                closeOnConfirm: false ,
                allowOutsideClick: true
              },
              function(){
                //確定,執行         
                $('.vendorWin').click();//點擊廠商編號
              });
              return; 
            }

     

  4.