JQ version
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function () { $("p").click(function () { $(this) .hide (); }); }); </ Script > </ head > < body > < the p- > If you and I, I will disappear. </ The p- > < the p- > continue to point me! </ The p- > < the p- > then point me! </ The p- > </ body > </ HTML >
JS version
<! DOCTYPE HTML > < HTML > < head > < Meta charset = "UTF-8" > < title > newbie tutorial (runoob.com) </ title > </ head > < body > < the p- > If you point me, I'll disappear. </ The p- > < the p- > continue to point me! </ The p- > < the p- > then point me! </ The p- > < Script > window.onload = function () { var ppp = document.getElementsByTagName("p"); console.log(ppp) if (ppp.length > 0) { for (var i = 0; i < ppp.length; i++) { console.log(ppp[i]) ppp[i].addEventListener("click", function () { this.hidden = true; }); } } } </script> </body> </html>
Have time to detail what js the event bubbling and event capture.