方法:1、在標簽的事件屬性內使用,語法“<標簽名 事件屬性名=“js代碼”>”;2、寫在script標簽對中,語法“<script>js代碼</script>”;3、使用“<script src="js代碼文件"></script>”語句。

本教程操作環境:windows7系統、javascript1.8.5版、Dell G3電腦。
js的使用方式和css類似:
1.行內式
在標簽屬性內使用 "";
<body onload="alert('hello world3')";> </body>
2.內嵌式
直接使用script標簽
<script> alert("hello world2"); </script>
3.鏈入式
使用<script type=“text/javascript”src=“js文件路徑”>引入外部.js文件
<script type="text/javascript" src="js學習.js"></script>
js文件代碼
alert("hello world 1");
【推薦學習:javascript高級教程】
站長資訊網