2016-02-26 63 views
0

我想要一个处理程序附加到删除按钮click事件,会弹出一个确认模式。 当确认它应该重定向到process.php?cid=$cid。 但是,如何将变量$cid传递给模态删除?如何传递变量来引导模式确认按钮使用jQuery

数据列表:

<?php 
    foreach($getChannel as $data) { 
?> 
<div class="btn-group btn-group-solid"> 
    <a class="btn red" data-toggle="modal" href="#small" id="<?php echo $cid?>"> 
    <i class="fa fa-trash"></i> Delete </a> 
</div> 
<?php 
    } 
?> 

模态:

<div class="modal fade bs-modal-sm" id="small" tabindex="-1" role="dialog" aria-hidden="true"> 
    <div class="modal-dialog modal-sm"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button> 
       <h4 class="modal-title">Confirm</h4> 
      </div> 
      <div class="modal-body"> 
       Are you sure to delete? 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn green" data-dismiss="modal" id="delcancel">cancel</button> 
       <button type="button" class="btn red" id="del" onclick="process.php?cid=$cid">Go Delete</button> 

      </div> 
     </div> 
    </div> 
</div> 

如何使用jQuery收到$ CID变量?

<button type="button" class="btn red" id="del" onclick="process.php?cid=$cid">Go Delete</button> 
+0

我希望我能标志一个问题的两倍。你的问题已经被问:http://stackoverflow.com/questions/34693206/how-can-i-pass-a-php-variable-to-bootstrap-modal?rq=1 [传的 –

+0

可能的复制PHP变量模态Twitter的引导不工作(http://stackoverflow.com/questions/23467669/passing-php-variable-to-modal-twitter-bootstrap-not-working) –

+0

的可能的复制[如何通过$ \从一个链接到一个bootstrapmodal _GET变量?](http://stackoverflow.com/questions/32433765/how-to-pass-get-variables-from-a-link-to-a-bootstrapmodal) – Shehary

回答

0
<button type="button" class="btn red" id="del" data-cid="<?php echo $cid; ?>">Go Delete</button> 

使用容纳你的$cid值自定义属性

$("button[data-cid!='']").click(function() { 
    var getCid = $(this).attr("data-cid"); // this returns $cid 
    //your statements what you wanna proceed with 
}); 

然后使用jQuery利用jQuery中你$cid值,tag with attribute选择使用在其具有的按钮来指定点击事件属性data-cid。针对click事件后,使用$(this)目标点击的当前元素检索属性.attr('data-cid')