我在HTML中的按钮,单击时,我需要它的索引属性值传递给我的点击收听:如何将数据传递给我的点击收听
<button class="btn buy-button js-prevent-cart-listener guys" index="1">Add To Cart</button>
和听众:
$('.girls').on('click', buyButtonGirlsClickHandler, index);
所以,当我运行这个功能,我可以访问事件值和函数中使用它:
function buyButtonClickHandler(evt) {
console.log(evt.value);
}
我不想将其更改为在该按钮上附加“onclick()”。这是可能的,如果是这样的话?显然上面的代码不能通过索引值,我已经尝试了很多次
'var index = this.getAttribute(“index”)' – Andreas