首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >twitter引导+ grails启动中断jquery

twitter引导+ grails启动中断jquery
EN

Stack Overflow用户
提问于 2014-10-10 11:43:03
回答 1查看 329关注 0票数 0

我正在使用grails在我的应用程序上添加twitter引导程序,这给jquery库带来了问题。我不能调用DOM对象上的函数:

我得到的是:

代码语言:javascript
复制
<script>

$(function()
{
    //Loads the modal when page loads
    $.post('${createLink(controller: 'task', action:'create')}',
    function(data)
    {
        $('#AndersonModal').html(data);
    }, "html");

    $('#andersonTest').click(function ()
        {
            console.log("modal button clicked");
            $('#AndersonModal').modal('show');
        });
});
</script>

<a id="andersonTest" href='#'>Anderson</a>

<div id="AndersonModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>

当我点击这个链接时,它会触发js,但是它说'modal‘不是一个函数。

代码语言:javascript
复制
TypeError: $(...).modal is not a function 1:129
Empty string passed to getElementById(). bundle-bundle_bootstrap_defer.js:4
"modal button clicked"

不管一切正常工作,调制解调器能工作,我只是不能用js来让它们出现.实际上,在DOM对象中添加函数的任何类型的库都会发生这种情况,如$('#someID').someFunction();。这总是同样的错误:

代码语言:javascript
复制
"TypeError: $(...).someFunction is not a function"

有人知道我该怎么解决这个问题吗?

我的应用程序上的插件:

代码语言:javascript
复制
plugins {
        build ":tomcat:7.0.52.1"
        compile ":scaffolding:2.0.3"
        compile ':cache:1.1.2'
        compile ':spring-security-core:2.0-RC4'
        compile ":mail:1.0.6"
        compile ":kickstart-with-bootstrap:1.1.0"
        compile ":rest:0.7"
        compile ":modernizr:latest.integration"
        compile ":uploadr:0.8.2"
        compile ":quartz:1.0.1"//latest.integration" //1.0.1"

        runtime ":hibernate:3.6.10.13" // or ":hibernate4:4.3.5.1"
        runtime ":database-migration:1.4.0"
        runtime ":jquery:1.11.0.2"
        runtime ":resources:1.2.7"
        runtime ':spring-security-acl:2.0-RC1'
    }

编辑:

正在使用的模块:

代码语言:javascript
复制
<g:javascript src="fastclick.js"/>
<r:require modules="jquery"/> <%-- jQuery is required for Bootstrap! --%>
<r:require modules="bootstrap"/>
<r:require modules="bootstrap_utils"/>

<r:layoutResources />
<g:layoutHead />
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-13 09:54:39

我发现发生这种情况是由于冲突,因为正在加载多个jQuery版本。因此,我需要使用jQuery.noConflict()来解决这个问题:

代码语言:javascript
复制
$('#andersonTest').click(function ()
    {
        $2 = jQuery.noConflict( true );
        console.log("modal button clicked");
        $2('#AndersonModal').modal('show');
    });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26298624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档