点击功能仅适用于我的中继器中的第一项,为什么?

Pau*_*iel 3 html javascript jquery dom-traversal

这是我的标记:

 <a href="#" id="buyMobileTickets" class="btn blue" data-ivaid="<%# ((MovieModel)Container.DataItem).FID %>">Buy Ticket(s)</a> 
Run Code Online (Sandbox Code Playgroud)

这是documentReady中的jquery

$(document).ready(function() {
$("#buyMobileTickets").on("click", mobileTickets);
});
Run Code Online (Sandbox Code Playgroud)

这是我的功能:

 function mobileTickets(e, ui) {      
        var ivaId = $(this).attr("data-ivaid");
        var theatre = Regal.userPrimaryTheatre;
        var movietDt = new Date();

        window.open("http://www.fandango.com/redirect.aspx?&a=12878&dte=0&mid=" + ivaId + "&tid=" + theatre , "_blank");

    }
Run Code Online (Sandbox Code Playgroud)

这只适用于我的转发器中的第一个数据元素,我做错了什么?

kap*_*apa 6

因为HTML中不应该有相同ID的元素.文档中始终可以有一个具有特定ID的元素.

你应该使用一个类:

<a href="#" class="buyMobileTickets btn blue" ...>Buy Ticket(s)</a>
Run Code Online (Sandbox Code Playgroud)

然后使用jQuery的类选择器:

$(".buyMobileTickets").on("click", mobileTickets);
Run Code Online (Sandbox Code Playgroud)