[JavaScript tutorial] JavaScript output

Source: Internet
Author: User
JavaScript does not have any printing or output functions. In HTML, JavaScript is usually used to operate HTML elements.

JavaScript output

JavaScript does not have any printing or output functions.

In HTML, JavaScript is usually used to operate HTML elements.

Operate HTML elements

To access an HTML element from JavaScript, you can use the document. getElementById (id) method.


Use the "id" attribute to identify HTML elements and innerHTML to obtain or insert element content:

Instance

My first Web page

My first paragraph

Script document. getElementById ("demo"). innerHTML = "the section has been modified. "; Script

The preceding JavaScript statement (in the script tag) can be executed in a web browser:

Document. getElementById ("demo") is the JavaScript code that uses the id attribute to search for HTML elements.

InnerHTML = "Paragraph changed." Is the JavaScript code used to modify the HTML content (innerHTML) of an element.

In this tutorial

In most cases, in this tutorial, we will use the method described above to output:

In the following example

Elements are written to HTML document output:

Write to HTML document

For testing purposes, you can write JavaScript directly in HTML documents:

Instance

My first Web page

My first paragraph.

Script document. write (Date (); script

Use document. write () to output only the written content to the document.

If you execute document. write after the document has been loaded, the entire HTML page will be overwritten.


Instance

My first Web page

My first paragraph.

Click meScript function myFunction () {document. write (Date ();} script

Write to console

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

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

Instance

My first Web page script a = 5; B = 6; c = a + B; console. log (c); script

Do you know?

Debugging in the program is the process of testing, finding and reducing bugs (errors.


The above is the content output by JavaScript in the [JavaScript tutorial]. For more information, see the PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.