开发者

jquery image click firing once

开发者 https://www.devze.com 2023-01-20 20:07 出处:网络
I have a page with 3 tabs on it.The first tab has a few cancel images with the class \"cancelBtn\". <img src=\"images/cancel.gif\" alt=\"Cancel Order\" class=\"cancelBtn\" id=\"49\" />

I have a page with 3 tabs on it. The first tab has a few cancel images with the class "cancelBtn".

<img src="images/cancel.gif" alt="Cancel Order" class="cancelBtn" id="49" />

The first time the page loads the click event fires fine, if I move away from the frist tab and return the click event doesn't fire. Each time a tab is clicked the html used on the tab including the cancel button is retrieved from the server.

Does anyone know why the event only fires on when the page is loaded? thanks

$(function () {
    $(".cancelBtn").click(function () {
        alert('hello');
        $.ajax({
            type: "POST",
            url: "Default.aspx/CancelOrder",
            data: "{}",
            contentType: "application/json; charset=utf-8",开发者_开发技巧
            dataType: "json",
            success: function (msg) {
                $("#divResult").html(msg.d);
            }
        });
    });
});


Each time a tab is clicked the html used on the tab including the cancel button is retrieved from the server.

The click() event assigns the function only to the elements that exist at the time when it's called. Use live to bind the event to "future" elements as well.

 $(".cancelBtn").live("click", function() {
0

精彩评论

暂无评论...
验证码 换一张
取 消