function tabsOpen(x) {
var tab = x;
return tab;
}
function printTab(x) {
var tabOpen = tabsOpen(tab);
alert(tabOpen);
}
Why does the second function doesnt show the returned value "tab" from the first one? Thanks!
function printTab(x) {
var tabOpen = tabsOpen(x);
alert(tabOpen);
}
Second function has x passed into it, but then tries to pass a different variable to tabsOpen, you need to pass x into that function as ' tab
' doesn't exist in it's scope.
Edit - Working code
Your javascript:
function tabsOpen(x) {
var tab = x;
return tab;
}
function printTab(x) {
var tabOpen = tabsOpen(x);
alert(tabOpen);
}
And your html:
<button onclick="printTab(5)">lol</button>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.