tess
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>helloWorld</title> <style> div{ text-align: center; font-size: 20px; } </style> </head> <body> <div id="hello">hello</div> </body> <script> var oDiv=document.getElementById('hello'); oDiv.onclick=function(){ alert('hello world!'); } </script> </html> 来源: https://www.cnblogs.com/jsll/p/11598642.html