gpt4 book ai didi

javascript - 如何在不同的按钮上绑定(bind)功能?

转载 作者:行者123 更新时间:2023-11-29 10:20:27 32 4
gpt4 key购买 nike

<分区>

我试图在我的按钮上绑定(bind)警报:

for(var i=1; i<=3; i++){
$('#' + i).live('click', function(){
alert(i);
});
};

这是我的html代码:

<input id="1" type="button" value="one">
<input id="2" type="button" value="two">
<input id="3" type="button" value="three">

但我在所有按钮上都得到 4。如何修复它以获得正确的警报值? (1、2、3 等等。)

http://jsfiddle.net/sergey1986/UFjsM/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com