开发者

How to use the value of the variable?

开发者 https://www.devze.com 2023-03-21 05:14 出处:网络
I do have a variable named \"movieTitle\". I used it inside the click event, but how can I use the value of that variable when I use it inside a function that is outside the event?

I do have a variable named "movieTitle". I used it inside the click event, but how can I use the value of that variable when I use it inside a function that is outside the event?

function addMovie(){
   $("Movie title is "+ movieTitle).appendTo("#output");
}

$("#insert").click(function(){
   var movieTitle = $("input#movie").val();
   add开发者_C百科Movie();
})

Thank you.


Pass it as argument:

function addMovie(movieTitle){
   $("#output").append("Movie title is "+ movieTitle).
}

$("#insert").click(function(){
   addMovie($("#movie").val());
})
0

精彩评论

暂无评论...
验证码 换一张
取 消