[removed] get a function's variable's value within another function

前端 未结 5 1466
故里飘歌
故里飘歌 2020-12-08 21:20

okay so I have this code in body:


And this code in script

<         


        
5条回答
  •  轮回少年
    2020-12-08 22:17

    Your nameContent scope is only inside first function. You'll never get it's value that way.

    var nameContent; // now it's global!
    function first(){
        nameContent = document.getElementById('full_name').value;
    }
    
    function second() {
        first(); 
        y=nameContent; 
        alert(y);
    }
    second();
    

提交回复
热议问题