我正在使用bootstrap弹出
这是我的代码:
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" id='2' data-toggle="modal" data-target="#myModal">Open Modal</button>
<button type="button" class="btn btn-info btn-lg" id='3' data-toggle="modal" data-target="#myModal">Open Modal</button>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
这里有两个按钮是打开相同的弹出窗口。我想要点击哪个按钮。我想要那个按钮id
有可能得到这个吗?
答案 0 :(得分:1)
是的,使用bootstrap模态event侦听器,
模态触发按钮
<button type="button" class="btn btn-info btn-lg" id='2' data-toggle="modal" data-target="#myModal">Open Modal</button>
<button type="button" class="btn btn-info btn-lg" id='3' data-toggle="modal" data-target="#myModal">Open Modal</button>
事件脚本
$(document).ready(function(){
$('#myModal').on('show.bs.modal', function (e) {
var id = $(e.relatedTarget).attr('id');
alert(id);
});
});
工作示例
$(document).ready(function() {
$('#myModal').on('show.bs.modal', function(e) {
var id = $(e.relatedTarget).attr('id');
alert(id);
});
});
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal" id='2'>Open Modal</button>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal" id='3'>Open Modal</button>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
&#13;
答案 1 :(得分:0)
<button type="button" class="btn btn-info btn-lg" id='2' ng-click="get_id_function(2)" data-toggle="modal" data-target="#myModal">Open Modal</button>
<button type="button" class="btn btn-info btn-lg" id='3'
ng-click="get_id_function(3)" data-toggle="modal" data-target="#myModal">Open Modal</button>
在javasscript中
$scope.get_id_function(id){}
因此您可以在函数参数id
中接收id