我的jQuery代码不起作用,在Firebug控制台中它说:“jQuery没有定义”。我已经检查过jQuery正在加载,但我仍然没有得到它显示错误的原因。
我的jQuery代码如下:
( function($) {
$(document).ready(function() {
$("form#add #divOptionsBlock .item img").css("visibility","hidden");
$('#divOptionsBlock .txtBoxStyle:first').change(function() {
var fpath = $("#divOptionsBlock .item img").attr("src") ;
var finalimage = 'http://shop.daactive.com/thumbnail.asp?file='+fpath+'&maxx=300&maxy=0';
var fpath2 = $("form#add img#large").attr("src",finalimage);
var imagepath_ahref="http://shop.daactive.com/"+fpath;
var fpath3 = $("form#add a#listing_main_image_link").attr("href",imagepath_ahref);
var fpath4 = $("form#add a#listing_main_image_link .MagicBoxShadow img").attr("src",imagepath_ahref);
var textvalue = $('#divOptionsBlock .txtBoxStyle:first option:selected').text()
$("#imagecaptiont").html(textvalue);
});
});
} ) ( jQuery );
答案 0 :(得分:3)
你没有包含jQuery!将其添加到<head>
或<body>
结束之前:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
答案 1 :(得分:0)
看起来你正在从http://shop.daactive.com/prototype.js而不是jQuery加载prototype.js(v 1.6.0.3)。
要继续使用原型,您需要为原型库而不是jQuery重构您的javascript:http://api.prototypejs.org/
如果您选择也包含jQuery,则需要在其“安全”模式下使用jQuery: http://docs.jquery.com/Using_jQuery_with_Other_Libraries
但是这意味着要加载2个javascript库,这可能是一大堆javascript要加载,考虑到页面加载时间。