简体   繁体   English

Bootstrap模态按钮不响应点击

[英]Bootstrap Modal buttons do not respond to click

I am having a mare with Bootstraps buttons in a modal popover. 我在模态弹出窗口中有一个带有Bootstraps按钮的母马。 Whatever I do I cannot get the click event to fire. 无论我做什么,我都无法点击事件。 Latest Bootstrap, jQuery 1.7.1. 最新的Bootstrap,jQuery 1.7.1。

Inside the modal I have a footer with buttons 在模态内部,我有一个带按钮的页脚

<div class="modal-footer">
  <a href="#" class="btn cancelBtn">Cancel</a>
  <a href="#" class="btn dontSaveBtn">Don't Save</a>
</div>

And my JS that is not working (click is never fired) 我的JS无法正常工作(点击永远不会被解雇)

$("#navigate-away .cancelBtn").on("click", function(event){
  console.log('Click.');
  $('#navigate-away').modal('hide');
});

I can prove it works by using hover instead of click (hover fires ok) 我可以通过使用悬停而不是点击来证明它的工作原理(悬停火力确定)

$("#navigate-away .cancelBtn").on("hover", function(event){
  console.log('Click.');
  $('#navigate-away').modal('hide');
});

It seems the click event is being swallowed internally? 似乎内部吞下了click事件? I see all over SO people using this exact method with no problems. 我看到所有SO人都使用这种精确的方法没有问题。 What simple thing am I missing? 我错过了什么简单的事情?

This did indeed to turn out to be a conflict with another library. 这确实是与另一个图书馆的冲突。 It was a shocker to debug, I ended up getting it relatively simply using Allan Jardine's Visual Event bookmarklet at http://www.sprymedia.co.uk/article/Visual+Event . 调试令人震惊,我最终在http://www.sprymedia.co.uk/article/Visual+Event上使用Allan Jardine的Visual Event bookmarklet相对简单。 Thanks Allan you saved my baconator. 谢谢艾伦,你救了我的熏肉。

Try adding preventDefault to your click event, and changing to use the delegate style of binding: 尝试将preventDefault添加到click事件,并更改为使用delegate样式的绑定:

$("#navigate-away").on("click", ".cancelBtn", function(event){
  event.preventDefault();
  console.log('Click.');
  $('#navigate-away').modal('hide');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM