0

此代码中的所有内容均正常运行,但浏览器在导入新内容后无法应用 jquery 功能

html代码:

<div class="id2" >  </div>

        <div style="clear: both"></div> <br/>

链接

                 <div class="read">
                <table cellpadding="0" cellspacing="0" id="table" width="100%">



            </table>
            </div>

jquery代码:此代码有2个函数第一个函数插入到数据库并导入新内容第二个函数将从数据库中删除并从表中隐藏tr删除了当此内容从第一个函数导入时用户无法从表中删除的问题,, jquery 函数不起作用

/ *删除并隐藏** /

    $(document).on("click", "#backup", function(){        // when  click 'the link'  this will import new content and update databace  and i use .on() function for it
  var s = {
      "id": "backup_tables"
        };
  $.ajax({         // here will do some thing in databacse
      url : "function.php",
      type : "POST",
      data :s,
      success : function (data){
         $(".id2").stop().stop().html(data).fadeIn(1000).delay(3000).fadeOut(500);    // here the massges for user will set in the class "id2"
      },
  });

      var s = {
      "id": "backup_readlast"
        };

  $.ajax({    // hrer will add new content
      url : "function.php",
      type : "POST",
      data :s,
      success : function (data){
      $(".read table tr:last").after(data);       // here will set the new content in the end of table and it's  working ,
      $("#table tr:last").hide().fadeIn(800);      // but The problem that the import content is not applies jquery code
      },
      beforeSend : function (){

       $(".id2").html("<img scr =\"../images/loading.gif\"  alt=\"\" />");

      }
});
return false;
});
      /*** delet and hide  ****/
 $(".backupdelete").click(function(){   // here this function must be work after import new content  ,, but desn't work
           var name = $(this).attr("title");
           var s = {
      "id": "backupdelete",
      "id2" : name
        };
  $.ajax({
      url : "function.php",
      type : "POST",
      data :s,
      success : function (data){
         $(".id2").stop().stop().html(data).fadeIn(500).delay(2000).fadeOut(500);  // here the massges for user will set in the class "id2"
      },
      beforeSend : function (){
       $(".id2").html("<img scr =\"../images/loading.gif\"  alt=\"\" />");
      }
  });
$(this).closest('tr').fadeOut(500);
return false;
});
4

1 回答 1

0

因此,在每种情况下都使用 on() :

  /*** delet and hide  ****/
  $('body').on('click',".backupdelete",function () { // here this function must be work after import new content  ,, but desn't work
      var name = $(this).attr("title");
      var s = {
          "id": "backupdelete",
              "id2": name
      };
      $.ajax({
          url: "function.php",
          type: "POST",
          data: s,
          success: function (data) {
              $(".id2").stop().stop().html(data).fadeIn(500).delay(2000).fadeOut(500); // here the massges for user will set in the class "id2"
          },
          beforeSend: function () {
              $(".id2").html("<img scr =\"../images/loading.gif\"  alt=\"\" />");
          }
      });
      $(this).closest('tr').fadeOut(500);
      return false;
  });
于 2013-03-30T10:31:49.033 回答