JavaScript output
JavaScript does not have any print or output functions
Data can be output in different ways
Use the Window.alert () pop-up warning box
Use the document.write () method to write content to an HTML document
Use document.getElementById (""). Innerhtml= "value to write"; Writing to HTML elements
Use Console.log () to write to the console of the rover
1: Use Window.alert ()
<script>
Window.alert (' warning box ');
</script>
2: Manipulating HTML elements
If you want JavaScript to access an HTML element, you can use the document.getElementById (ID) method
Use the id attribute to identify the HTML element and innerHTML to get or insert the element content:
<p id= "Demo" > my first paragraph </p>
<script>
document.getElementById ("Demo"). Innerhtml= "paragraph modified"
</scirpt>
document.getElementById ("Demo") is the JavaScript code that uses the id attribute to find HTML elements. The method is defined in the HTML DOM.
InnerHTML = "Paragraph changed." Is the JavaScript code used to modify the HTML content (InnerHTML) of an element.
3: Write to HTML document
Use the document.write () method to write content to HTML content, which can be written directly to the HTML document with content or HTML tags
<script>
Docuemnt.write (Date ());//date () Output China standard Time
</script>
Note: If you execute document.write () after the document has finished loading, the entire HTML page will be overwritten
Sample:
<button type= "button" onclick= "MyFunction" > Buttons </buton>
<script>
function MyFunction () {
document.write (Date ());
}
</scipt>
4: Write to console
If your browser supports debugging, you can use the Console.log () method to display JavaScript values in the browser.
In the browser, use F12 to enable debug mode and click the "Console" menu in the Debug window.
<! DOCTYPE html>
<body>
<script>
A = 5;
b = 6;
c = a + B;
Console.log (c);
</script>
</body>
Attention:
The Console.log () method allows you to see the output from your page, making it easier to debug JavaScript, and the console doesn't interrupt your page when compared to alert, and the console contains a lot of content, and you can enter console in the console.
Four ways to Output Javascript