【问题标题】:jQuery is not defined and could not find whyjQuery 未定义,找不到原因
【发布时间】:2012-05-24 12:33:01
【问题描述】:

我的 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 );

【问题讨论】:

  • 可能是这个提问者看到的奇怪的东西,特别是如果它只在 Firefox 4 中。stackoverflow.com/questions/10605780/…
  • 你链接到 jQuery 文件了吗?
  • 是的,我已经在 firebug NET 中检查过它的加载情况
  • @Imran 不,我认为您没有包含 jQuery。
  • 我查看了您的源代码,但找不到 jQuery。你能告诉我你链接到哪里吗?哪一行?

标签: javascript jquery


【解决方案1】:

你没有包含 jQuery!将此添加到您的<head><body> 末尾之前:

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

【讨论】:

    【解决方案2】:

    看起来您正在从http://shop.daactive.com/prototype.js 加载prototype.js(v 1.6.0.3)而不是jQuery。

    要继续使用原型,您需要为原型库而不是 jQuery 重构 javascript:http://api.prototypejs.org/

    如果您也选择包含 jQuery,则需要在“安全”模式下使用 jQuery: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

    但这意味着要加载 2 个 javascript 库,并且要加载大量的 javascript,需要记住页面加载时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 2015-01-04
      • 1970-01-01
      • 2019-02-26
      • 2018-10-18
      • 2014-04-26
      • 2014-09-26
      相关资源
      最近更新 更多