2017-09-30 33 views
0

我使用https://craftpip.github.io/jquery-confirm/#customizing插件作爲彈出窗口。我只需要一個幫助當用戶點擊Confirm按鈕時,爲什麼它不重定向?如果我使用alert();那麼它正在顯示。動作函數不工作在jQuery中 - 確認

該函數沒有獲取id值。

你能幫我嗎?

<!DOCTYPE html> 
<html> 
    <head> 
    <title></title> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.css"> 
    </head> 
    <body> 
    <?php 
     $delete_id=2; 
    ?> 
    <a href="javascript:void(0);" onClick="warning('<?php echo $delete_id;?>')" class="cross-cta"> 
     <i class="fa fa-times" aria-hidden="true"></i> 
    </a> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.js"></script> 
    <script type="text/javascript"> 
     function warning($id){ 
     $.confirm({ 
      title: 'DELETE SELECTED!', 
      content: 'Are you sure?.', 
      type: 'red', 
      typeAnimated: true, 
      theme: 'material', 
      buttons: { 
      tryAgain: { 
       text: 'Confirm', 
       btnClass: 'btn-red', 
       action: function(){ 
       window.location='mypage?action=empty&deletekey='+id+''; 

       } 
      }, 
      close: function() {} 
      } 
     }); 
     } 
    </script> 
    </body> 
</html> 
+0

try do window.location.href =「http://example.com/mypage?action=empty&delekeykey=」+ id; –

+0

@AmitVagner,我試過但沒有工作 –

+0

onClick =「warning('<?php echo $ delete_id;?>')」這個問題。 –

回答

0

最後我發現我的問題。 這一行的問題是function warning($id){。我使用$ id instated of id。 我必須像這樣使用function warning(id),它的工作完美。