jQuery after AJAX Postback
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?
精彩评论