不同button打开同一个bootstrap模态框,需要传入一个flag来区分

不同的按钮打开同一个id=myModal的模态框,有时候需要传入一个参数(flag)来进行区分是哪一个按钮打开的

那么直接上代码了

第一个按钮button属性里面加入data-whatever="add"

<button id="sure_pre_release_draft" type="button" data-toggle="modal" data-target="#myModal" data-whatever="add" class="btn btn-primary btn-sm">
    <span class="glyphicon glyphicon-plus"></span>
</button>

第一个按钮button属性里面加入data-whatever="edit"

<button id="sure_pre_release_draft" type="button" data-toggle="modal" data-target="#myModal" data-whatever="edit" class="btn btn-primary btn-sm">
    <span class="glyphicon glyphicon-plus"></span>
</button>

然后通过模态框触发事件来获取

$("#myModal").on("show.bs.modal",function(e){
    //获得点击打开的按钮
    var button=$(e.relatedTarget);
    //根据标签获得按钮传入的参数
    var recipient=button.data("whatever");
    //console.log(recipient);
    if(recipient == "edit"){
    	do something.............
    }
    if(recipient == "add"){
    	do something.............
    }
});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值