【问题标题】:Twitter Bootstrap + Mootools + JQuery.NoConflict() problems while trying to use popoverTwitter Bootstrap + Mootools + JQuery.NoConflict() 在尝试使用 popover 时出现问题
【发布时间】:2011-12-18 15:58:13
【问题描述】:

我有 mootools 和 Twitter Bootstrap(它使用 JQuery 来实现其 Javascript 功能)在 bootstrap-dropdown.js 中使用 JQuery.NoConflict() 几乎“运行良好”。

好吧,现在我正在尝试使用 bootstrap-popover.js,但它的运行不如 bootstrap-dropdown.js 顺利。好吧,我想这是一个我无法很好理解的兼容模式问题。

我有这个 javascript 错误:

<script type="text/javascript">
$(function () {
  $('td[rel=popover]')
    .popover({
      offset: 10,
      live: true
    })
    .click(function(e) {
      e.preventDefault()
    })
})
</script> 

错误是:

Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function

编辑:

我之前已经成功使用过popover(但没有使用mootools),我尝试重复相同的方式和代码。就在此 javascript 代码出现错误之前,我正在链接这样的文件(已成功加载):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="../js/html5.js"></script>
<script src="../js/bootstrap-dropdown.js"></script>
<script src="../js/bootstrap-alerts.js"></script>
<script src="../js/bootstrap-twipsy.js"></script>
<script src="../js/bootstrap-popover.js"></script>
<script src="../js/bootstrap-modal.js"></script>
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css" />

我知道在&lt;head&gt;&lt;/head&gt; 之间应该会更好,但它在&lt;body&gt; 内部应该也可以工作,并且它适用于其他bootstrap-alerts.jsdropdown。 另外,我在&lt;table&gt; 中以这种方式调用弹出框:

<thead>
    <tr>
        <th>Título</th>
        <th>Data</th>
        <th>Horário</th>
        <th rel="popover" data-original-title="A title" data-content="And here's some amazing content. It's very engaging. right?">Ticket Associado <img src="../img/alert-icon.gif"></th>
        <th>Entrar no Chat</th>
    </tr>
</thead>

在 twitter-Bootstrap/JQuery 之后调用 mootools。

有什么帮助吗?提前非常感谢您!

【问题讨论】:

    标签: javascript jquery mootools twitter-bootstrap


    【解决方案1】:

    嗯。似乎 twitter 弹出框代码有问题,比任何事情都更有可能。

    Property '$' of object [object DOMWindow] is not a function - 听起来好像 $ 不是你想象的那样。我认为 noConflict 的重点是恢复使用 jQuery() 而不是 $ - 您发布的代码并没有完全做到这一点。

    相反 - 如果在 jquery 之后加载并且版本为 1.2.3 或更高版本,mootools 将不会接管 $ 声明并回退到 document.id

    你什么时候得到异常、运行时或者你什么时候与弹出元素交互?执行console.log(window.$) 并查看已声明它的内容,听起来它是原始对象属性而不是函数。

    您是否运行任何需要使用 $ 的特定 mootools 东西?需要比您提供的更多的数据。

    您可能想看看这里的 BootStrap 的 MooTools 端口:http://dev.clientcide.com/?version=MooTools%20Bootstrap - 仍在进行中,但它有重要的东西。

    【讨论】:

    • Chirstoff,我添加了一些关于 confs 和环境的更多信息。感谢您的帮助和耐心:)
    • 在哪里加载 mootools 以及哪个版本?当您执行 console.log(window.$) 和 console.log($.toString()) 时会发生什么 - jquery 或 mootools 有它还是别的什么?您还说您在引导下拉菜单中使用了它。为弹出框提供的代码看起来并不安全 - 它依赖于 $ 是 jquery。
    猜你喜欢
    • 2013-11-01
    • 2015-02-26
    • 2011-11-26
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 2011-05-22
    相关资源
    最近更新 更多