方法:1、在標(biāo)簽的事件屬性內(nèi)使用,語(yǔ)法“<標(biāo)簽名 事件屬性名=“js代碼”>”;2、寫(xiě)在script標(biāo)簽對(duì)中,語(yǔ)法“<script>js代碼</script>”;3、使用“<script src="js代碼文件"></script>”語(yǔ)句。
本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
js的使用方式和css類似:
1.行內(nèi)式
在標(biāo)簽屬性內(nèi)使用 "";
<body onload="alert('hello world3')";> </body>
2.內(nèi)嵌式
直接使用script標(biāo)簽
<script> alert("hello world2"); </script>
3.鏈入式
使用<script type=“text/javascript”src=“js文件路徑”>引入外部.js文件
<script type="text/javascript" src="js學(xué)習(xí).js"></script>
js文件代碼
alert("hello world 1");
【推薦學(xué)習(xí):javascript高級(jí)教程】