我有这个bootstrap模式包含一个带有close类的按钮,它关闭了模态,我打算用这个按钮来改变window.location不仅仅是关闭模态,请帮助:
<div class='modal fade' id='alert' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header bg-primary'>
<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>×</span></button>
<h4 class='modal-title'> Hello world/h4>
</div>
<div class='modal-body'>
<p>Hello world </p>
</div>
<div class='modal-footer'>
<button class='btn btn-default' data-dismiss='modal' >Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
//jquery to change location doesn't work?
<script>
$('.close').click(function()
{
if($('.close').click())
{
window.location.href = 'http://www.example.com/product.asp?IDnum=1';
}
});
答案 0 :(得分:1)
从data-dismiss
按钮中删除close
属性。您需要将位置脚本放在document.ready
函数中。
请注意,关闭按钮的ID应为close
$(function() {
$('#close').click(function() {
window.location.href = 'http://www.example.com/product.asp?IDnum=1';
});
});
这是demo。