我正在尝试在列表内的按钮上添加事件,但似乎只有列表上的第一个按钮正在注册 onclick 事件。没有显示错误,但我不明白为什么只有按钮的第一部分正在注册事件?这里是:
<ul id = "button-list">
<li>
<button class = "buttons" id = "first" name = "ltrContainer" ></button>
</li>
<li>
<button class = "buttons" id = "second" name = "ltrContainer" ></button>
</li>
<li>
<button class = "buttons" id = "third" name = "ltrContainer" ></button>
</li>
<li>
<button class = "buttons" id = "fourth" name = "ltrContainer" ></button>
</li>
<li>
<button class = "buttons" id = "fifth" name = "ltrContainer" ></button>
</li>
<li>
<button class = "buttons" id = "sixth" name = "ltrContainer" ></button>
</li>
</ul>
只有第一个按钮正在注册一个事件,这是我的 JQuery 代码
$('.buttons').click(function(){
textContainer.value += this.innerHTML;
alert(this.innerHTML);
});