jQuery學習總結05-事件
阿新 • • 發佈:2018-07-10
tex class query har code color jquer lang his
1.事件的發生
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <input id="t1" type="text" /> <input id="a1" type="button" value="添加" /> <ul id="u1"> <li>1</li> <li>2</li> </ul> <script src="jquery-1.12.4.js"></script> <script> $(‘#a1‘).click(function () { var v = $(‘#t1‘).val(); var temp = "<li>" + v + "</li>"; $(‘#u1‘).append(temp); });// $(‘ul li‘).click(function () { // var v = $(this).text(); // alert(v); // }) // $(‘ul li‘).bind(‘click‘,function () { // var v = $(this).text(); // alert(v); // }) // $(‘ul li‘).on(‘click‘, function () { // var v = $(this).text();// alert(v); // }) //以上對於新增加的標簽,都無法添加點擊事件,只有如下可以 $(‘ul‘).delegate(‘li‘,‘click‘,function () { var v = $(this).text(); alert(v); }) </script> </body> </html>
2.
jQuery學習總結05-事件