2017-05-05 48 views
-1

我有這樣的代碼:確認模式jQuery的引導

點擊此鏈接:

<td><?php echo anchor("atendimento/delete/{$record->id}", 'Excluir', ['class'=>'btn btn-danger', 
          'name' => 'delete', 'id' => 'anchordelete']); ?></td> 

顯示有兩個按鈕SimNao,其中Sim意味着是和Nao一個模式是指號如果我點擊在Sim需要從數據庫中刪除數據。

<div class="modal fade" role="dialog" id="myModal"> 
    <div class="modal-dialog"> 
     <!-- Modal content--> 
      <div class="modal-content" > 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal">&times;</button> 
       <h4 class="modal-title">Atenção</h4> 
      </div> 
      <div class="modal-body"> 
       <p id="confirm-message"></p> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-danger" id="confirm">Sim</button> 
       <button type="button" class="btn btn-default" data-dismiss="modal" id="cancel">Não</button> 
      </div> 
      </div> 
    </div> 
    </div> 

jQuery(document).ready(function() { 

    $("a[name='delete']").on('click', function(e){ 

     $("#confirm-message").html("Confirma a EXCLUSÃO do registro?"); 
     $('#myModal').modal("show"); 

     e.preventDefault(); 
    }); 

    $('#confirm').on('click', function(){ 

      $("a[name='delete']").trigger('click'); 
      $("a[name='delete']").removeAttr("name"); 

      $('#myModal').modal("hide"); 
    }); 

}); 

不工作,當我點擊Nao,模態接近,但如果我在Sim點擊,什麼都沒有發生。

編輯:

,這裏是我的PHP循環

<?php if(count($records)){ ?> 

        <?php foreach($records as $record) {?> 
         <tr> 
          <td><?php echo $record->data; ?></td> 
          <td><?php echo $record->assunto; ?></td> 
          <td><?php echo $record->responsavel; ?></td> 

          <td><?php echo anchor("atendimento/edit/{$record->id}", 'Atualizar', ['class'=>'btn btn-success']); ?> </td> 
          <td><?php echo anchor("atendimento/delete/{$record->id}", 'Excluir', ['class'=>'btn btn-danger', 
          'name' => 'delete', 'id' => 'anchordelete']); ?></td> 

         </tr> 
        <?php }?> 
       <?php } ?> 
+0

你有多個'#anchordelete'上點擊過的URL模式?你試過'$(「#anchordelete」)。trigger('click')'? – madalinivascu

+0

你是對的一件事...我有多個ID相同的名稱..現在我編輯..但同樣的問題 – HawkB

+0

你需要找到刪除按鈕基於確認按鈕 – madalinivascu

回答

-1

使用window.location的去刪除頁,使用數據屬性

jQuery(document).ready(function() { 

    $("a[name='delete']").on('click', function(e){ 

     $("#confirm-message").html("Confirma a EXCLUSÃO do registro?"); 
     $('#myModal').attr('data-url',$(this).attr('href')); 
     $('#myModal').modal("show"); 

     e.preventDefault(); 
    }); 

    $('#confirm').on('click', function(){ 
      window.location = $(this).closest('#myModal').attr('data-url') 
    }); 

}); 
+0

thnx爲信任投票:) – madalinivascu

+1

非常感謝你!!!!! UAU!驚人! – HawkB

0

用途:

$("#anchordelete")[0].click(); 

jQuery的.click()將嘗試添加一個單擊處理程序,而不是實際點擊的元素。使用[0]將引用第一個元素,然後單擊它。

+0

仍然不工作... – HawkB

+0

'console.log($('## anchordelete'))'。它工作嗎? – FrankerZ

+0

是的這是工作 – HawkB