append追加元素后click失效

莫问天涯路几重,轻衫侧帽且从容。这篇文章主要讲述append追加元素后click失效相关的知识,希望能为你提供帮助。

< !DOCTYPE html> < html lang="en"> < head> < meta charset="UTF-8"> < meta name="viewport" content="width=device-width, initial-scale=1.0"> < meta http-equiv="X-UA-Compatible" content="ie=edge"> < title> Document< /title> < script src="http://img.readke.com/220509/03402613a-0.jpg"> < /script> < /head> < body> < ul class="type_list" id="type_list_1"> < li class="active"> 全部< /li> < /ul> < span class="test"> 测试< /span> < /body> < script> $(function() { $(‘#type_list_1 li‘).click(function(event) { console.log(‘123‘); }); $(‘#type_list_1 li‘).on(‘click‘, function() { console.log(‘456‘); }); $(document).on(‘click‘, ‘#type_list_1 li‘, function() { console.log(‘789‘); }); $(‘.test‘).click(function() { $(‘#type_list_1‘).append(‘< li> 歌剧< /li> ‘); }); }); < /script> < /html>

【append追加元素后click失效】 

    推荐阅读