Function is not defined - uncaught referenceerror

前端 未结 7 1937
滥情空心
滥情空心 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:

    <input type="image" src="btn.png" alt="" id="img-clck" />
    

    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.

    0 讨论(0)
提交回复
热议问题