2013年10月7日 星期一

BlockUI 按鈕綁定

<!-- BlockUI 確認 取消  -->
<div id="<portlet:namespace/>questionBox" style="display: none; cursor: default">
 <h1>是否確認刪除?</h1>
 <input type="button" class="button_2" id="<portlet:namespace/>yes" value="是" /> <input type="button" class="button_2" id="<portlet:namespace/>no" value="否" />
</div>



function del(elem) {
//清空按鈕事件,避免重複註冊
   $('#yes').unbind( "click" );
   $('#no').unbind( "click" );
   
 //綁定Yes按鈕事件
 $('#<portlet:namespace/>yes').click(function() {
   //使用選擇器 選到要刪除的<tr>
   var row = $(elem).parent().parent().parent().parent();
 
   var summonsNo = row.find('input[name*=summonsNo]').val();
   var companyCode = row.find('input[name*=companyCode]').val();
   
    $.ajax({
       url : '${deletSSMPage}',
       datatype : 'JSON',
       data:{'summonsNo':summonsNo,"companyCode":companyCode},
       type : 'POST',
       async : true,
       cache : false,
       error : function(XMLHttpRequest, Status, errorThrown) {
       },
       success : function(data) {
       //由於 有傳data到後端,view 會把傳到後端的物件又轉成json傳到前端,所以要+上key data.result
       if (data.result.success) {
         //移除被刪除的那行
            row.remove();
       }else{
            
       }
         
       }
    });
 
  $.unblockUI();
    
 });
 
 //綁定No按鈕事件
 $('#no').click(function(){$.unblockUI();})
   
 //顯示確認視窗
 $.blockUI({ message: $('#questionBox'), css: { width: '300px' } });

}


沒有留言:

張貼留言