論壇網(wǎng)站地圖怎么做指定關鍵詞seo報價
這里寫目錄標題
- 前情提要
- JavaScript書寫位置
- 1. 內部javaScript ==(不常用)==
- 2. 外部javaScript ==(常用)==
- 3.內聯(lián)javaScript ==(常用)==
- js中的輸入和輸出
- 輸出語法
- 1. document.write('')
- 2. alert('')
- 3. console.log('')
- 輸入語法
- prompt('')
前情提要
1. 在javaScript中的 分號 是可以省略的
JavaScript書寫位置
1. 內部javaScript (不常用)
直接寫在html文件里 , 用script標簽包住
通常放在html文件中的底部—>文件是按順序加載的 , 要先加載完上面的代碼 , 再執(zhí)行js的代碼
<script type="text/javascript">console.log('hello word!');
</script>
- 全部 .html 文件
<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title></title><script type="text/javascript">console.log('hello word!');</script></head><body></body>
</html>
- 運行結果
2. 外部javaScript (常用)
<script type="text/javascript" src="js/js01.js"></script>
- html文件代碼
<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title></title><script type="text/javascript" src="js/js01.js"></script></head><body></body>
</html>
- js文件代碼
console.log('hello wwwww');
-
運行結果
-
創(chuàng)建一個 .js文件 (用來書寫js代碼)
3.內聯(lián)javaScript (常用)
代碼寫在標簽內部
<button onclick="alert('啊哈哈哈')">點一下</button>
- 完整 .html
<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title></title></head><body><button onclick="alert('啊哈哈哈')">點一下</button></body>
</html>
- 運行結果
js中的輸入和輸出
輸出語法
1. document.write(‘’)
作用 : 向body內輸出內容
注意 : 如果輸出的內容寫的是標簽 , 也會被解析成網(wǎng)頁元素(也就是說 , 可以在write中直接寫 標簽)
- .js 文件
document.write('這是document.write');
document.write('<h1>這是一個h1的標簽</h1>');
上面的js代碼相當于 在html中這么寫
<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title></title></head><body>這是documen.write<h1>這是一個h1標簽</h1></body>
</html>
- 運行結果
2. alert(‘’)
- 作用 : 頁面彈出警告對話框
3. console.log(‘’)
- 作用 : 在控制臺輸出內容 (一般是程序員調試用的)
這兩個在上面的js書寫位置中用到了 , 就不做過多贅述了
輸入語法
prompt(‘’)
-
作用 : 顯示一個對話框 , 對話框中包含一條文字信息 , 用來提示用戶輸入文字
-
js代碼
prompt('請輸入一個信息');
- 運行結果