append追加元素後click失效
阿新 • • 發佈:2018-08-23
script ctype console ini log ble query jquer tle
<!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="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></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失效