-1
如何獲得這段JavaScript代碼停止迭代的最後數花的刪除功能?清單上的JavaScript
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="lista"></div>
</body>
<script type="application/javascript">
var dados = ['vassoura','lixo','papel'];
function deletar(elemento){
console.log(elemento);
}
function listar(){
var div = document.getElementById('lista');
for(i in dados){
campo = document.createElement("output");
button = document.createElement("button");
button.addEventListener("click",()=>{
deletar(dados[i]);
});
button.innerHTML="deletar";
div.appendChild(campo);
div.appendChild(button);
console.log(i);
campo.value = dados[i]+" ";
console.log(dados[i]);
}
}
listar();
</script>
他經過最後的相應數量的迭代爲什麼當我按一下按鈕迭代已經取得並完成
請只交英格爾問題更換
for(i in dados)
。或者您的問題發佈在https://pt.stackoverflow.com/ –我投票關閉這個問題題外話,因爲https://pt.stackoverflow.com/ – epascarello
真正的問題是一個欺騙的https:/ /stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example – epascarello