JavaScript簡(jiǎn)介
有一張圖片小小介紹吧,想要詳細(xì)了解點(diǎn)擊:JavaSCript 百科

JavaScript輸出
JavaScript 沒(méi)有任何打印或者輸出的函數(shù)。
JavaScript 顯示數(shù)據(jù)
JavaScript 可以通過(guò)不同的方式來(lái)輸出數(shù)據(jù):
- 使用 window.alert() 彈出警告框。
- 使用 document.write() 方法將內(nèi)容寫到 HTML 文檔中。
- 使用 innerHTML 寫入到 HTML 元素。
- 使用 console.log() 寫入到瀏覽器的控制臺(tái)。
使用window.alert()
你可以彈出警告框來(lái)顯示數(shù)據(jù):
實(shí)例
><!DOCTYPE html>
<html>
<body>
><h1>我的第一個(gè)頁(yè)面</h1>
<p>我的第一個(gè)段落。</p>
><script>
window.alert(5 + 6);
</script>
></body>
</html>```
[編輯運(yùn)行](http://www.runoob.com/try/tryit.php?filename=tryjs_output_alert)
####***操作 HTML 元素***
________
如需從 JavaScript 訪問(wèn)某個(gè) HTML 元素,您可以使用```document.getElementById(id) ```方法。
**id**屬性標(biāo)識(shí) HTML 元素, **innerHTML** 獲取或插入元素內(nèi)容:
>**實(shí)例**
<!DOCTYPE html>
<html>
<body>
<h1>我的第一個(gè) Web 頁(yè)面</h1>
<p id="demo">我的第一個(gè)段落</p>
<script>
document.getElementById("demo").innerHTML = "段落已修改。";
</script>
</body>
</html>
[編輯運(yùn)行](http://www.runoob.com/try/try.php?filename=tryjs_console)
####***寫到 HTML 文檔***
___________________
>**實(shí)例**
<!DOCTYPE html>
<html>
<body>
<h1>我的第一個(gè) Web 頁(yè)面</h1>
<p>我的第一個(gè)段落。</p>
<script>
document.write(Date());
</script>
</body>
</html>
[編輯運(yùn)行](http://www.runoob.com/try/tryit.php?filename=tryjs_output_alert)
**注意**:
請(qǐng)使用 document.write() 僅僅向文檔輸出寫內(nèi)容。如果在文檔已完成加載后執(zhí)行 document.write,整個(gè) HTML 頁(yè)面將被覆蓋。
>**實(shí)例**
<!DOCTYPE html>
<html>
<body>
<h1>我的第一個(gè) Web 頁(yè)面</h1>
<p>我的第一個(gè)段落。</p>
<button onclick="myFunction()">點(diǎn)我</button>
<script>
function myFunction() {
document.write(Date());
}
</script>
</body>
</html>
[編輯運(yùn)行](http://www.runoob.com/try/tryit.php?filename=tryjs_output_alert)
####***寫到控制臺(tái)***
___________________
如果您的瀏覽器支持調(diào)試,你可以使用 console.log() 方法在瀏覽器中顯示 JavaScript 值。
瀏覽器中使用 F12 來(lái)啟用調(diào)試模式, 在調(diào)試窗口中點(diǎn)擊 "Console" 菜單。
>**實(shí)例**
<!DOCTYPE html>
<html>
<body>
<h1>我的第一個(gè) Web 頁(yè)面</h1>
<script>
a = 5;
b = 6;
c = a + b;
console.log(c);
</script>
</body>
</html>
[編輯運(yùn)行](http://www.runoob.com/try/tryit.php?filename=tryjs_output_alert)