开发者

Jquery Rebind function after Ajax call

开发者 https://www.devze.com 2023-01-25 15:06 出处:网络
I have a problem. The click event that summons a greybox form is broken after a div is refreshed. How to I rebind the function to the refreshed content, that includes the links that will re-fire the g

I have a problem. The click event that summons a greybox form is broken after a div is refreshed. How to I rebind the function to the refreshed content, that includes the links that will re-fire the greybox? I am assuming I have to re-initialize the functions after the click event. I am a newbie so thans for your help.

    <script type="text/javascript" src="js/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="js/greybox.js"></script>
<script type="text/javascript">
      var GB_ANIMATION = true;
      $(document).ready(function(){
        $("a.greybox").click(function(){
          var t = this.title || $(this).text() || this.href;
          GB_show(t,this.href,470,600);
          return false;
        });
      });

</script>

<script type="text/javascript">  
    function update(){
  开发者_Go百科    jQuery("#showdata").load("maincontentdiv.php<?php echo $passme;?>");
      }

function GB_hide2() {
  $("#GB_window,#GB_overlay").hide();
    $("#GB_window").remove();
    update();


}


The 'click' binding and other bindings in jQuery only bind once when called to a specific DOM element. To ensure that dynamically loaded content is also bound, use the 'live' method:

$("a.greybox").live('click',function(){
...


Ok I have added the .live method, now when the element refeshes, when I click on the EDIT button that triggers the greybox, only the grey overly loads.

<script type="text/javascript" src="js/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="js/greybox.js"></script>
<script type="text/javascript">
      var GB_ANIMATION = true;
      $(document).ready(function(){
        $("a.greybox").live('click',function(){ 
          var t = this.title || $(this).text() || this.href;
          GB_show(t,this.href,470,600);
          return false;

        });
      });
</script>

<script type="text/javascript">  
    function update(){
      jQuery("#showdata").load("maincontentdiv.php<?php echo $passme;?>");
      }

</script>

<script type="text/javascript">  
function GB_hide2() {
  $("#GB_window,#GB_overlay").hide();
    $("#GB_window").remove();
    update();
}
</script>
0

精彩评论

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