我正在使用grails在我的应用程序上添加twitter引导程序,这给jquery库带来了问题。我不能调用DOM对象上的函数:
我得到的是:
<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‘不是一个函数。
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();。这总是同样的错误:
"TypeError: $(...).someFunction is not a function"有人知道我该怎么解决这个问题吗?
我的应用程序上的插件:
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'
}编辑:
正在使用的模块:
<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 />发布于 2014-10-13 09:54:39
我发现发生这种情况是由于冲突,因为正在加载多个jQuery版本。因此,我需要使用jQuery.noConflict()来解决这个问题:
$('#andersonTest').click(function ()
{
$2 = jQuery.noConflict( true );
console.log("modal button clicked");
$2('#AndersonModal').modal('show');
});https://stackoverflow.com/questions/26298624
复制相似问题