我想在“删除”按钮上附加一个处理程序到click
个事件,这将弹出一个确认模式。
确认后,它应重定向到process.php?cid=$cid
。
但是如何将变量$cid
传递给模态删除?
数据清单:
<?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 :(得分: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')
值