链接点击事件无效

时间:2014-12-22 11:06:28

标签: javascript jquery

点击“商店”点击

后,“商品”点击事件无效
<div class="i_find">
    <div class="replaced_link">Goods</div>
    <div class="link_container"><a href="#" class="a_shops">Shops</a></div>
</div>

完整代码:http://jsfiddle.net/01j2s7xj/12/

1 个答案:

答案 0 :(得分:1)

您需要在此处使用事件委派:

$("body").on('click','.a_shops',function(){ 
    $('.i_find div:eq(0)').replaceWith('<div class="link_container"><a class="a_goods" href="#">Goods</a></div>');
    $('.i_find div:eq(1)').replaceWith('<div class="replaced_link">Shops</div>');

});

$("body").on('click','.a_goods',function(){
    $('.i_find div:eq(0)').replaceWith('<div class="replaced_link">Goods</div>');
    $('.i_find div:eq(1)').replaceWith('<div class="link_container"><a class="a_shops" href="#">Shops</a></div>');
}); 

<强> Working Demo