JavaScript輸出定義了顯示給定代碼輸出的方式。能夠經過如下四種不一樣的方式顯示輸出:html
語法以下:前端
document.getElementById(id)
例子:本示例使用innerHTML顯示數據。正則表達式
<!DOCTYPE html> <html> <head> <title> JavaScript Output using innerHTML </title> </head> <body> <h1>lsbin</h1> <h2> JavaScript Display Possibilities Using innerHTML </h2> <p id = "GFG"></p> <!-- Script to uses innerHTML --> <script> document.getElementById("GFG").innerHTML = 10 * 2; </script> </body> </html>
輸出以下:測試
語法以下:spa
document.write()
例子:本示例使用document.write()屬性顯示數據。調試
<!DOCTYPE html> <html> <head> <title> JavaScript Output using document.write() </title> </head> <body> <h1>lsbin</h1> <h2> JavaScript Display Possibilities Using document.write() </h2> <p id = "GFG"></p> <!-- Script to uses document.write() --> <script> document.write(10 * 2); </script> </body> </html>
輸出以下:code
語法以下:htm
window.alert()
例子:本示例使用window.alert()屬性顯示數據。ip
<!DOCTYPE html> <html> <head> <title> JavaScript Output using window.alert() </title> </head> <body> <h1>lsbin</h1> <h2> JavaScript Display Possibilities Using window.alert() </h2> <p id = "GFG"></p> <!-- Script to use window.alert() --> <script> window.alert(10 * 2); </script> </body> </html>
輸出以下:開發
語法以下:
console.log()
例子:本示例使用console.log()屬性顯示數據。
<!DOCTYPE html> <html> <head> <title> JavaScript Output using innerHTML </title> </head> <body> <h1>lsbin</h1> <h2> JavaScript Display Possibilities Using console.log() </h2> <p id = "GFG"></p> <!-- Script to use console.log() --> <script> console.log(10*2); </script> </body> </html>
輸出以下:
更多前端開發相關內容請參考:lsbin - IT開發技術:https://www.lsbin.com/
查看如下更多Scala相關的內容: