Function is not defined - uncaught referenceerror

前端 未结 7 1980
滥情空心
滥情空心 2020-12-03 02:32

I have this uncaught referenceerror function is not defined error which do not understand.

If I have

$(document).ready(function(){
 function codeAddr         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 03:28

    How about removing the onclick attribute and adding an ID:

    
    

    And your script:

    $(document).ready(function(){
        function codeAddress() {
            var address = document.getElementById("formatedAddress").value;
            geocoder.geocode( { 'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                }
            });
        }
        $("#img-clck").click(codeAddress);
    });
    

    This way if you need to change the function name or whatever no need to touch the html.

提交回复
热议问题