繁体   English   中英

javascript函数调用锚标记停止工作后

[英]After a javascript function call anchor tag stop working

我正在使用javascript函数,该函数保存ajax请求。 而且我也有一个锚标签。 页面加载时-显示的项目列表和出现添加新项目的按钮

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>

以上两个代码都描述了整个情况。

在ajax之后添加的项目不与JQuery事件绑定,您必须像这样绑定它们:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM