function iptDom() {
var iptValue = getIptValue();
console.log(iptValue)
AddUl();
createHintContent();
}
function getIptValue() {
// 注意获取input中的内容要用value
return emailIpt.value;
}
function AddUl() {
for(j = 0,len=postfixList.length; j < len; j++) {
let li = document.createElement('li');
li.innerText = `${iptValue}${postfixList[j]}`;
emailWrapper.appendChild(li);
}
}
请问这个iptValue变量为什么报错未定义?我的理解是addUl()函数里使用的这个iptValue变量应该能从外层作用域(iptDom这个函数作用域)里获取到,请问我的理解哪里有错误
你好,无论函数在哪里被调用,也无论它如何被调用,它的词法作用域都只由函数被声明时所处
的位置决定。我建议你将AddUl函数定义在iptDom里面,我觉得问题就能解决掉了。你试试。