我多張元素具有相同ID的多個元素得到名稱
<a href='#' id='Favorites[]' name='Favorites1'>1</a>
<a href='#' id='Favorites[]' name='Favorites2'>2</a>
<a href='#' id='Favorites[]' name='Favorites..'>..</a>
<a href='#' id='Favorites[]' name='Favorites1000'>1000</a>
I trying to get name of clicked element
$("#Favorites").on('click', function() {
alert(this.name);
});
但它僅適用於第一要素,其他要素不是點擊事件作出反應
如何修復?