2011-06-06 55 views
1

我是jQuery的新手。我试图转换这个jQuery代码,以便在我的页面中调用.Net Ajax部分回发之后它仍然存在。下面的代码在页面最初加载时运行,但不是在updatePanel中执行回发后运行。使用jQuery .Live来坚持.Net UpdatePanel部分回发不工作

我是否需要在我的代码中的其他地方使用.live功能才能使其工作?

代码:

<script type="text/javascript"> 

    $.noConflict(); 

$(document).ready(function() { 


    //Default Action 
    $(".tab_content").hide(); //Hide all content 
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab 
    $(".tab_content:first").show(); //Show first tab content 

    //On Click Event 

    $("ul.tabs li").live('click', (function() { 
     $("ul.tabs li").removeClass("active"); //Remove any "active" class 
     $(this).addClass("active"); //Add "active" class to selected tab 
     $(".tab_content").hide(); //Hide all tab content 
     var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content 
     $(activeTab).fadeIn(); //Fade in the active content 
     return false; 
    })); 

}); 


</script> 
+0

有点困惑,你打电话给'noConflict',然后在那之后使用'$',你说它可以工作...... – 2011-06-06 02:37:14

+0

哦对不起 - 忘了告诉你,我在页面中有另一个jQuery应用程序并不得不使用noConflict来让它工作 – 2011-06-06 04:16:04

回答

1

一个更好的选择可能是钩PageRequestManager的add_pageLoaded事件。这是描述如何做的an article。然后把jQuery的东西放在一个方法中并在事件中调用它。

+0

感谢罗布。你的链接让我对这个主题进行了更多的搜索,并且我找到了一个很棒的教程。这真的帮助我了解回传的差异。 这里链接: http://www.mindfiresolutions.com/jQuery-and-Asynchronous-Postback-with-UpdatePanel-Issue-635.php 我希望这可以帮助别人在未来。 Regards, Edward – 2011-06-07 16:08:19