我正在生成一些輸入,並向它們中的每個添加事件偵聽器,當我將注意力集中在每個值時如何增加值* 2?更改值並添加事件偵聽器
這裏是我已經有了:
for (var i = 0; i < 3; i++) {
var input = document.createElement("input");
document.body.appendChild(input);
random = Math.floor((Math.random() * 100) + 1);
this.input.value = random;
input.addEventListener('focus', function(e) {
this.value += random * 2;
})
}
你已經附加了一些代碼,似乎是它的問題? – Itay
你的意思是'this.value = this.value * 2;'? –
是的,這就是我的意思,我的錯誤。 – Bybnovskiy