Jquery代码在Joomla中不起作用,尝试了在google上找到的所有东西

Jquery代码在Joomla中不起作用,尝试了在google上找到的所有东西,jquery,joomla,Jquery,Joomla,我想用span包装我的img,并将图像设置为span的背景图像,这样我就可以对图像执行一些css技巧。我找到了这个密码 <script type="text/javascript"> $(document).ready(function(){ $("img").load(function() { $(this).wrap(function(){ return '<span class="image-wrap ' + $(this

我想用span包装我的img,并将图像设置为span的背景图像,这样我就可以对图像执行一些css技巧。我找到了这个密码

<script type="text/javascript">
$(document).ready(function(){

    $("img").load(function() {
        $(this).wrap(function(){
            return '<span class="image-wrap ' + $(this).attr('class') + '"'+'style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
        });
        $(this).css("opacity","0");
    });
});
</script>

$(文档).ready(函数(){
$(“img”).load(函数(){
$(this).wrap(function(){
返回“”;
});
$(this.css(“不透明度”,“0”);
});
});
它在一个html文件中运行得非常好。 但是,当我将此代码添加到我的~/template/index.php时,它不起作用,浏览器报告:

未捕获的TypeError:对象#没有方法“就绪”

似乎Jquery没有正确加载,我尝试将以下代码添加到index.php中:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

还尝试安装jQueryEasy插件并启用它,但都没有成功


出了什么问题?

在这里查看一个类似的问题/解决方案:


您可以像这样在模板中添加jquery-


您可以像这样在页面中添加jquery-

$document->addScriptDeclaration(“ //
$(文档).ready(函数()
{
$(“img”).load(函数(){
$(this).wrap(function(){
返回“”;
});
$(this.css(“不透明度”,“0”);
});
}))

//]]>

也可以在模板索引页面中这样声明jquery-


baseurl?>/templates/template;?>/您的JS文件夹/Java Script.JS“>看,这听起来像是一个类似的情况。你能提供一个到你网站的链接吗,否则请检查是否有2个jquery文件正在导入,因为这可能会导致Joomla发生冲突!您正在使用的版本?gwww。。。我什么都试过了。。没有一个奏效。我尝试使用您给我的代码,尝试用jquery替换$,但它仍然报告“未捕获引用错误:未定义jquery”,默认情况下它使用mootools。也许你有冲突。这里有3篇文章解决了这个问题:,您是否尝试过用jQuery(不是jQuery)替换$?检查资本化这最终奏效了:var$j=jQuery.noConflict();在jquery代码之前添加上述代码,并用$j替换$
<script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/YOUR_TEMPLATE_NAME/PATH_TO_JAVASCRIPT_FOLDER/YOUR_JQUERY.js"></script>

YOUR TEMPLATE - Name of you template
PATH TO JAVASCRIPT FOLDER - If any folder present then the path of the folder
YOUR JQUERY.js - Finally the file name which one you want to include.
$(document).ready(function()
{
    $("img").load(function(){
    $(this).wrap(function(){
        return '<span class="image-wrap ' + $(this).attr('class') + '"'+'style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
    });
    $(this).css("opacity","0");
});