gpt4 book ai didi

javascript - Jquery/Javascript 附加不运行

转载 作者:行者123 更新时间:2023-11-28 11:35:47 25 4
gpt4 key购买 nike

我正在测试这个 jQuery 代码,但它没有运行。我打开控制台(F12),粘贴测试代码后,它完美地编译了它。当我删除 src="http://code.jquery.com/jquery-latest.min.js"并从 $(document).ready(function(){ 中获取警报时,警报会起作用,但我明白了来自控制台的消息:“Uncaught ReferenceError:$未定义”。我想知道为什么会这样?有什么帮助吗?

这是我的测试代码:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">


$(document).ready(function(){
alert('Hi!');
$("#content").append('<div class=\'toolbarBox toolbarHead\' style=\'background-color: #F8F8F8;border: 1px solid #CCCCCC;margin-bottom: 10px;padding: 5px 0;border-radius: 3px;-moz-border-radius: 3px;-webkit-border-radius: 3px;-o-border-radius: 3px;position: relative;\'><div class=\'pageTitle\'><h3 style = \'font-size: 1.6em;font-weight: normal;line-height: 52px;text-shadow: 0 1px 0 #fff;\'><span id=\'current_obj\' style=\'font-weight: normal;\'><span class=\'breadcrumb item-0\'>My Affiliates<img alt=\'&gt;\' style=\'margin-right:5px\' src=\'../img/admin/separator_breadcrumb.png\'></span><span class=\'breadcrumb item-1\'>Affiliates</span></span></h3></div></div>');
$("#content").append("<iframe style=\'width: 100%;height: 100%;\' src=\'http://www.myaffiliates.gr/\'></iframe>");

});

最佳答案

您的脚本标签不正确

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
// your script
</script>

脚本元素可以包含 src 或 body,但不能同时包含两者。

Script : src

This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.

关于javascript - Jquery/Javascript 附加不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21676146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com