今天給repeater用JS寫一個hover事件
<script type="text/javascript"> $(function(){ $('.trhead').click(function(){ $(this).next('.trcontent').find('.divcontent').slideToggle('fast'); }); $('.trhead').hover(function(){$(this).css("background",'rgb(215,215,215)');}, function(){$(this).css("background",'#fff');} ); }) </script>
結果 repeater翻到第二頁后,效果失效了,也就是JS沒了。
這個時候,就在
protected void AspNetPager3_PageChanged(object sender, EventArgs e) { BindData(); //綁定數據后重新注冊一下JS事件 ScriptManager.RegisterClientScriptBlock(up1, GetType(), "aa", "aa()", true); }
而這個aa()函數呢,當然啦,就是:
<script type="text/javascript"> function aa() { $('.trhead').click(function(){ $(this).next('.trcontent').find('.divcontent').slideToggle('fast'); }); $('.trhead').hover(function(){$(this).css("background",'rgb(215,215,215)');}, function(){$(this).css("background",'#fff');} ); } </script>
也就是把onload要執行的JS,放到一個方法aa()中,在分頁綁定數據后,重新注冊一下即可。
同理,當別的控件回傳后,也需要重新注冊下即可。
Over~