bootstrap popover preventDefault for click在Rails 3.2应用程序中不工作 [英] bootstrap popover preventDefault for click is not working in a Rails 3.2 app

查看:97
本文介绍了bootstrap popover preventDefault for click在Rails 3.2应用程序中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在此这里提出这个问题,但没有给出答案或解决方案。



这些引导文件列在我的application.js文件的顶部:

  ... 
// = require bootstrap-tooltip
// = require bootstrap-popover
...

我的bootstrap_additions.js.coffee文件包含:

  $一个[rel = popover])。popover()
$(。tooltip)。tooltip()
$(a [rel = tooltip])。tooltip()



在视图中我有:

 < a href =#class =btn =popovertitle =Titledata-content =Some content。> click< / a> 

当我在浏览器中输入localhost:3000 / assets / application.js时,引导程序弹出。 js内容。此外,我发现以下:

  jQuery(function(){
$(a [rel = popover] ).popover()。on('click',preventDefault());
$(。tooltip)。tooltip();
return $(a [rel = tooltip] .tooltip();
});

点击链接时,浏览器显示被移动到页面顶部。当我向下滚动到链接时,将显示popover。除了preventDefault外,所有都工作。






更新:为了在代码中保持干净,我发现所选答案的 coffeescript版本

  $(a [rel = popover])。popover()。click(e)=> e.preventDefault()


解决方案

http://twitter.github.com/bootstrap/javascript.html#popovers\"> Twitter Bootstrap Popover



更新为Coffeescript



第一种方法



实例化

  $(a [rel = popover])。popover()

处理

  $(a [rel = popover]事件)→> 
event.preventDefault()
event.stopPropagation()
$(this).popovershow

第二种方法



直接从其源代码获取:

  $(a [rel = popover])。popover()。 
e.preventDefault()


Someone else asked this question here, but there was no answer or solution given.

These bootstrap files are listed at the top of my application.js file:

...
//= require bootstrap-tooltip
//= require bootstrap-popover
...

My bootstrap_additions.js.coffee file contains:

$("a[rel=popover]").popover()
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()

In a view I have:

<a href="#" class="btn" rel="popover" title="Title" data-content="Some content.">click</a>

When i enter localhost:3000/assets/application.js in the browser, the bootstrap-popover.js content is present. In addition i found the following:

jQuery(function() {
    $("a[rel=popover]").popover().on('click', preventDefault());
    $(".tooltip").tooltip();
    return $("a[rel=tooltip]").tooltip();
});

When the link is clicked the browser display is moved to the top of the page. When I scroll back down to the link, the popover is displayed. All is working except preventDefault. What am I missing?

Thanks.


UPDATE: To keep things clean in my code, i found the coffeescript version of the selected answer:

$("a[rel=popover]").popover().click (e) => e.preventDefault()

解决方案

Using Twitter Bootstrap Popover

Updated to be in Coffeescript

1st approach

Instantiate

$("a[rel=popover]").popover()

Handle

$("a[rel=popover]").click (event) ->
  event.preventDefault()
  event.stopPropagation()
  $(this).popover "show"

2nd approach

Taken directly from their source code:

$("a[rel=popover]").popover().click (e) ->
  e.preventDefault()

这篇关于bootstrap popover preventDefault for click在Rails 3.2应用程序中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆