草庐IT

nameContent

全部标签

javascript:在另一个函数中获取函数变量的值

好的,所以我在正文中有这段代码:脚本中的这段代码functionfirst(){varnameContent=document.getElementById('full_name').value;}functionsecond(){first();y=nameContent;alert(y);}second();我想要一个显示元素full_name值的警报,但它似乎不起作用,有人知道为什么吗?:S 最佳答案 nameContent仅存在于first()函数中,正如您在first()函数中定义的那样。为了扩大它的范围,在函数之外定义它