Home > Web Front-end > JS Tutorial > body text

What are the javascript output statements?

青灯夜游
Release: 2023-01-04 09:34:54
Original
14876 people have browsed it

Output statement: 1. "window.alert(content)"; 2. "document.write(content)"; 3. "document.getElementById("id value").innerHtml="content"" ;4. "console.log(content)".

What are the javascript output statements?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript output statement

1. Use window.alert() to output

<script>
window.alert(&#39;警告框&#39;);
</script>
Copy after login

2. Use the innerHTML attribute to output

If you need JavaScript to access an HTML element, you can use the document.getElementById(id) method

Please use the id attribute To identify HTML elements, and innerHTml to get or insert element content:

<p id="demo" >我的第一个段落</p>
<script>
document.getElementById("demo").innerHTML="段落已修改"
</scirpt>
Copy after login

document.getElementById("demo") is JavaScript code that uses the id attribute to find HTML elements. This method is defined in the HTML DOM.
innerHTML = "Paragraph changed." is the JavaScript code used to modify the HTML content (innerHTML) of the element.

[Recommended learning: javascript advanced tutorial]

3. Use docuemnt.write() to output

The document.write() method can write content into HTML content. This function can directly write content or html tags into html documents

<script>
docuemnt.write(Date());//Date()输出中国标准时间
</script>
Copy after login

4. Use console.log output

If your browser supports debugging, you can use the console.log() method to display JavaScript values ​​in the browser.

Use F12 in the browser to enable debugging mode, and click the "Console" menu in the debugging window.

What are the javascript output statements?

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of What are the javascript output statements?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template