2014-01-14 49 views
0

我正在使用JavaScript函数,该函数包含ajax请求。 ,我也有一个锚标签。 当页面加载,一个项目的列表中显示和按钮添加新的项目出现在JavaScript函数调用锚标记后停止工作

1.when i click on and item then it shows item detail. 
2.then i click on add new buttom and form to add item shown. 
3.but when i again click on any item it works fine but after that add 
new item stop working. 

javascript函数:

function Detail(ths,e){ 
    $(ths).siblings().removeClass('active'); 
     $(ths).addClass('active'); 
    var id = $(ths).attr('id'); 
     storage.setItem('itemId',id); 

if(!e.target) 
    { 
    var top = $(ths).position().top; 
    $('.list').scrollTop(top-100);  
} 

    if(!$(e.target).hasClass('action')) 
    { 
     $.ajax({ 
     url : "manage-details.php", 
     type: "POST", 
     data: {id:id} , 
     success: function(text) {   
      $("#rightsec").html(text); 
     } 
     }) 
    } 
} 

锚代码:

<a title="Add Items" id="additems" class="" href="#!manage-items.php|add-items.php"> 
     <span > 
     </span> 
     <span >Add Items</span> 
    </a> 

两个以上验证码描述整个条件。

回答

0

项目后添加AJAX不使用jQuery事件绑定,你必须将它们绑定这样的:

$("body").on("click", "h2", function() { 
    // Do something 
}); 

文件在这里:) http://api.jquery.com/on/