【发布时间】:2013-05-08 20:29:49
【问题描述】:
我想用 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>
它在单个 html 文件中运行良好。 但是,当我将此代码添加到我的 ~/template/index.php 时,它不起作用并且浏览器报告:
Uncaught TypeError: Object # has no method 'ready'
似乎 Jquery 没有正确加载,我尝试将以下代码添加到我的 index.php:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
还尝试安装 Jquery Easy 插件并启用它,但它们都不起作用。
怎么了?
【问题讨论】:
-
见this question 听起来情况类似。
-
您能否提供指向您网站的链接,否则请检查是否正在导入 2 个 jquery 文件,因为这可能会导致冲突
-
哪个 Joomla!你用的是什么版本?