行内式的js 直接写到元素的内部
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <input type="button" value="唐伯虎" onclick="alert('秋香姐')" /> </body> </html>
内嵌式的js
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> </body> <script type="text/javascript"> alert('唐伯虎点秋香'); </script> </html>
外部js
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="js/01.js" type="text/javascript" charset="utf-8"></script> </head> <body> </body> </html>
js文件:
alert('向往的生活');