Home > Article > Web Front-end > How to type javascript output statement
Writing method: 1. "window.alert(value)", the warning box output; 2. "document.write(value)", write the content into the HTML document; 3. "Element.innerHTML=" The value "" is written to the HTML element; 4. "console.log(value)", the console output.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JS output statement
Use window.alert() to write the warning box
Use document.write() writes HTML output
Use innerHTML to write HTML elements
Use console.log() to write browser control Taiwan
Use window.alert()
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>使用window.alert()写入警告框</title> </head> <body> <h1>使用window.alert()写入警告框</h1> <p>打开或刷新当前网页的时候会弹出一个警告框!</p> <script> window.alert("点击该警告框的确定按钮之后才会显示网页内容!"); </script> </body> </html>
Use document.write()
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>使用document.write()</title> </head> <body> <h1>使用document.write()</h1> <p>下方内容是使用document.write()写入的</p> <script> document.write("使用document.write()会直接在网页上输出内容"); </script> </body> </html>
Use innerHTML
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>使用innerHTML往元素内写入内容</title> </head> <body> <h1>使用innerHTML</h1> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = "这段文字是通过innerHTML写入的"; </script> </body> </html>
Use console.log()
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>使用console.log()在浏览器控制台输出内容</title> </head> <body> <h1>使用console.log()</h1> <p>在浏览器控制台输出内容</p> <script> console.log("使用console.log()在浏览器控制台输出内容"); </script> </body> </html>
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to type javascript output statement. For more information, please follow other related articles on the PHP Chinese website!