开发者

jQuery after AJAX Postback

开发者 https://www.devze.com 2023-02-13 04:18 出处:网络
After suffering from events that were no longer firing aftera partial AJAX Postback I modified all of my .bind() functions to .live().I therefore have this:

After suffering from events that were no longer firing after a partial AJAX Postback I modified all of my .bind() functions to .live(). I therefore have this:

$(document).ready(function() 
{ 
    var listBox = $("#<%=listBox.ClientID 开发者_开发技巧%>");
    var btnDropDown = $("#<%=btnDropDown.ClientID %>");
    var listBoxWrapper = $("#<%=ListboxWrapper.ClientID %>")
    var inputBox = $("#<%=inputBox.ClientID %>")

    btnDropDown.live("click", function () {
        listBoxWrapper.not(":animated").slideDown("fast");
        listBox.focus();
    });

    listBoxWrapper.live("focusout", function () {
        listBoxWrapper.slideUp("fast");
    });

    listBoxWrapper.live("click", function () {
        var inputtedText = listBox.val();
        inputBox.val(inputtedText)
        listBoxWrapper.slideUp("fast");
    });
});

Using alert() boxes I can now be sure that the click events are still firing event after a postback (the intended result) however the .slidedown("fast") still appears to not work. Any ideas on what the problem is?


The list of items in listBoxWrapper is populated at DOMReady. If items have been added to the DOM at a later point, that would match the selector, they would not be in that collection.

Look for the items when you need them, if they were not in the document during DOMReady:

btnDropDown.live("click", function () {
    $("#<%=ListboxWrapper.ClientID %>").not(":animated").slideDown("fast");
    $("#<%=listBox.ClientID %>").focus();
});


Does an alert on listBoxWrapper.not(":animated").length return any matched elements. This is the one that isn't working yes?

0

精彩评论

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