boostrap模态更改位置onClick不要解雇

时间:2015-11-20 03:35:59

标签: javascript twitter-bootstrap-3

我有这个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'>&times;</span></button>
        <h4 class='modal-title'>&nbsp;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';
    }
});

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