2011-07-25 13 views
1

の後にイベントハンドラが配線されません。問題:新しい挿入Dom要素が正しく配線されていません。これはIEでのみ発生し、新しい要素はDOMにのみ追加されます。ライブAjax Update、新しいDOM要素(Internet Explorer)

$(function(){ 
     $("#boxer img").live("click", function(){ 
      deletepost($(this).attr("name")); 
     }); 

     $('#postentry').submit(function() { 
      var tyu = $('#tittle_ent').val(); 
      if(tyu.length <= 2) 
      {alert('Enter More Text!'); return false;}else 
      { 
       $.ajax({ 
        type:'post', 
        url: '/posts_in.php', 
        dataType: "json", 
        data: $("#postentry").serialize(), 
        success:function(data){ 
         var tittle = data[0]; 
         var id= data[1];       
         $('<div></div>').attr('id','post'+id).addClass('boxee').html(tittle).prependTo('#boxer');       
         $('<img src="img/page-text-delete-icon.png" name="'+id+'">').attr({id:'postchk'+id,onclick: 'deletepost(this.name);'}).appendTo('#post'+id);       
         $('#tittle_ent').val('').focus(); 

        } 
       }); 
       return false; 
      } 
     }); 
    }); 

答えて

1

使用しjqueryのは、 'onclickの' 特にjqueryのを使用しているとき、古代/オールドスクールなものです。代わりに、このバリアントを試してみてください:

$('<img src="img/page-text-delete-icon.png" name="'+id+'">') 
    .attr('id', 'postchk'+id) 
    .click(function() { deletepost(this.name); }) /// use .click() instead. 
    .appendTo('#post'+id);       
0

$(function(){ 
     $('#postentry').submit(function() { 
      var tyu = $('#tittle_ent').val(); 
      if(tyu.length <= 2) 
      {alert('Enter More Text!'); return false;}else 
      { 
       $.ajax({ 
        type:'post', 
        url: '/posts_in.php', 
        dataType: "json", 
        data: $("#postentry").serialize(), 
        success:function(data){ 
         var tittle = data[0]; 
         var id= data[1];       
         $('<div></div>').attr('id','post'+id).addClass('boxee').html(tittle).prependTo('#boxer');       
         $('<img src="img/page-text-delete-icon.png" name="'+id+'">').attr({id:'postchk'+id,onclick: 'deletepost(this.name);'}).appendTo('#post'+id);       
         $('#tittle_ent').val('').focus(); 

        } 
       }); 
       return false; 
      } 
     }); 
    }); 
関連する問題