我的 Bootstrap 弹出窗口有问题。我有一个按钮,当我单击它时,它会显示一个表单。在表单中有一个按钮,我希望当我单击此按钮时,它会发出警报。但是当我点击它时,它不会发出任何警报。我不知道为什么它不起作用,你能帮助我吗?谢谢大家!
<script src="//code.jquery.com/jquery.js"></script>
<!-- Latest compiled and minified CSS & JS -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$('#form_popover #ok').click(function(){
alert("hi");
});
$('.btn-open-popover').popover();
// //popover option
$("#a-popover").popover({
title: 'Dang ki thong tin',
content: $('#divContentHTML').html(),
placement: 'right',
html: true
});
});
</script>
<link rel="stylesheet" media="screen" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
<a href="#" class="btn btn-default" id="a-popover">Click!</a>
<div id="divContentHTML" style="display:none">
<form method="post" id="form_popover">
<div class="form-group form-inline kc">
<label for="">Name</label>
<input type="text" class="form-control" id="user" placeholder="Input field">
<label for="">Email</label>
<input type="text" class="form-control" id="email" placeholder="Input field">
</div>
<button type="button" id="ok" class="btn btn-primary">OK</button>
</form>
</div>
</div>
最佳答案
由于此按钮是动态加载(或重新初始化)的,因此您应该使用委托(delegate)事件处理程序。例如:
$(document).on('click', '#ok', function()
{
alert("hi");
});
Fiddle .
或者使用 static <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
会好一点:
$('.col-xs-5').on('click', '#ok', function()
{
alert("hi");
});
Fiddle .
关于jquery - 我无法单击 Bootstrap 弹出窗口中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26418318/