Function is not defined - uncaught referenceerror

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

    You must write that function body outside the ready();

    because ready is used to call a function or to bind a function with binding id like this.

    $(document).ready(function() {
        $("Some id/class name").click(function(){
            alert("i'm in");
        });
    });
    

    but you can't do this if you are calling "showAmount" function onchange/onclick event

    $(document).ready(function() {
        function showAmount(value){
            alert(value);
        }
    
    });
    

    You have to write "showAmount" outside the ready();

    function showAmount(value){
        alert(value);//will be called on event it is bind with
    }
    $(document).ready(function() {
        alert("will display on page load")
    });
    

提交回复
热议问题