$是未定义的jQuery和Bing Map API

时间:2013-09-16 19:12:17

标签: javascript jquery undefined bing-maps

所以我遇到了Bing Maps API中信息框高度的问题。我正在加载的内容超出了标准。所以我想我会尝试使用jQuery获取outerHeight并相应地更改div的高度。

我似乎遇到错误,错误为“$ is undefined”。我很确定我正确地按正确的顺序加载库。关于为什么我仍然会收到此错误的任何想法?

<head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
       <script type="text/javascript"> 
            var infoBoxHeight = $('#infobox-info').outerHeight();

然后我尝试提醒infoBoxHeight,但我一直得到“$ is undefined”。感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

尝试使用http://而不是//。我总是这样做但只是因为它有时在我的开发计算机上不起作用,具体取决于浏览器。看看这个网站,我找到了一个解释:

来自Synchro帖子this的引文:

  

更一般的解释是匿名协议URL不能   孤立地工作;必须有相关的背景。在典型的网络中   因此,以这种方式引入脚本库是很好的,但任何方式   外部链接应始终指定协议。我做了一个简单的尝试   test://stackoverflow.com映射到文件:///stackoverflow.com   浏览器我试过它,所以它们真的不能单独工作。

Is there any downside for using a leading double slash to inherit the protocol in a URL? i.e. src="//domain.com"

我希望它可以帮到你。如果你发现我没有为这个答案做出贡献,请告诉我。

别的。我在本地尝试了并在Chrome中检查了javascript控制台,它不起作用,错误很明显:

无法加载资源文件://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js 未捕获的ReferenceError:$未定义Index.html:8

它在本地寻找图书馆。

答案 1 :(得分:0)

我建议摆脱

script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"

在你的“text / javascript”里面放了这个

var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js";
document.getElementsByTagName('meta')[0].appendChild(jq);

jq.onload = procede;//make sure you don't type parenthesis

//i.e. 'procede()' runs function instantly
//     'procede' gives it a function to run when it's ready

...

function procede()
{
//jQuery commands are loaded (do your magic)


}