#JavaScript的三种使用方式#
1.行内式
index.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js</title> </head> <body> <input type="button" value="测试" οnclick="javascript:alert('hello world!')"> <!--行内--> </body> </html>
2.内嵌式
index.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js</title> <script> alert("hello JS!");<!--内嵌--> </script> </head> <body> <input type="button" value="测试" οnclick="javascript:alert('hello world!')"> <!--行内--> </body> </html>
3.外链式(引入)
t_js.js:
alert("hello JS!");
index.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js</title> <script src="js/t_js.js"></script> <!--引入--> <script> alert("hello JS!");<!--内嵌--> </script> </head> <body> <input type="button" value="测试" οnclick="javascript:alert('hello world!')"> <!--行内--> </body> </html>