简体   繁体   English

ReferenceError:未定义$

[英]ReferenceError: $ is not defined

This is my code which does the functionality of auto address fill up and identifying the chosen latitude/longitude/address. 这是我的代码,用于执行自动地址填充和识别所选纬度/经度/地址的功能。

<html>

<head>
<LINK rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
</head>

<body>
<p>Location: <input type="text" id="searchTextField" size="50"  placeholder="Where do you want to go ?"/></p>

<div id="results"></div>

<script>


var input = document.getElementById('searchTextField');
var options = {

};
var autocomplete = new google.maps.places.Autocomplete(input,options);
//autocomplete.bindTo('bounds', map); 

google.maps.event.addListener(autocomplete, 'place_changed', function() {
     $("#results").html('');
  var place = autocomplete.getPlace();
    $("#results").append('<p> Latitude and Longtidute : '+place.geometry.location +'</p>');
    $("#results").append('<p> Address : '+place.formatted_address +'</p>');
    $("#results").append('<p> Places Name : '+place.name+'</p>');

    var searchAddressComponents = place.address_components;
    $.each(searchAddressComponents, function(){
    if(this.types[0]=="postal_code"){
        searchCountry=this.short_name;
    } 
});
});
</script>
</body>
</html>

i thought everything is correct but it throws this error in firebug ReferenceError: $ is not defined 我以为一切都正确,但是在萤火虫ReferenceError中抛出了此错误:$未定义

can you please help me with it 你能帮我吗

please check http://jsfiddle.net/NuCUd/8/ for reference 请检查http://jsfiddle.net/NuCUd/8/以供参考

$ is defined by jQuery, which is an ordinary, 3rd-party library. $由jQuery定义,它是一个普通的第三方库。

If you don't include it, it won't exist. 如果不包括它,它将不存在。

Change your code to: 将您的代码更改为:

<html>

<head>
<LINK rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
</head>

<body>
<p>Location: <input type="text" id="searchTextField" size="50"  placeholder="Where do you want to go ?"/></p>

<div id="results"></div>

<script>


var input = document.getElementById('searchTextField');
var options = {

};
var autocomplete = new google.maps.places.Autocomplete(input,options);
//autocomplete.bindTo('bounds', map); 

google.maps.event.addListener(autocomplete, 'place_changed', function() {
     $("#results").html('');
  var place = autocomplete.getPlace();
    $("#results").append('<p> Latitude and Longtidute : '+place.geometry.location +'</p>');
    $("#results").append('<p> Address : '+place.formatted_address +'</p>');
    $("#results").append('<p> Places Name : '+place.name+'</p>');

    var searchAddressComponents = place.address_components;
    $.each(searchAddressComponents, function(){
    if(this.types[0]=="postal_code"){
        searchCountry=this.short_name;
    } 
});
});
</script>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM