<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js"> </script> <script> $(document).ready(function(){ $("body").on('click','p',function(){ $(this).hide(); }); }); </script> </head> <body> <p>如果您點擊我,我會消失。</p> <p>點擊我,我會消失。</p> <p>也要點擊我哦。</p> </body> </html>
<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js"> </script> <script> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> <body> <p>如果您點擊我,我會消失。</p> <p>點擊我,我會消失。</p> <p>也要點擊我哦。</p> </body> </html>
注意1,2代碼區別,方式1,后期動態添加的<p>標簽是可以點擊消失的,方式2不行
