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

时间:2022-11-29 10:28:00

Here is my markup:

这是我的标记:

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

here is the jquery in documentReady

这是documentReady中的jquery

$(document).ready(function() {
$("#buyMobileTickets").on("click", mobileTickets);
});

here is my function:

这是我的功能:

 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");

    }

This works only for the first data element in my repeater, what am I doing wrong?

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

1 个解决方案

#1


6  

Because there should be no elements with the same ID in HTML. There can always be one element with a specific ID in a document.

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

You should use a class instead:

你应该使用一个类:

<a href="#" class="buyMobileTickets btn blue" ...>Buy Ticket(s)</a>

and then the class selector with jQuery:

然后使用jQuery的类选择器:

$(".buyMobileTickets").on("click", mobileTickets);

#1


6  

Because there should be no elements with the same ID in HTML. There can always be one element with a specific ID in a document.

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

You should use a class instead:

你应该使用一个类:

<a href="#" class="buyMobileTickets btn blue" ...>Buy Ticket(s)</a>

and then the class selector with jQuery:

然后使用jQuery的类选择器:

$(".buyMobileTickets").on("click", mobileTickets);