0 Basic JavaScript encoding (i)

Source: Internet
Author: User

Mission Purpose

    • JavaScript Beginner Experience
    • Initial understanding of JavaScript's simple basic syntax, such as variables, functions
    • What is the initial understanding of JavaScript events?
    • Get a basic idea of what DOM is in JavaScript

Task description

    • Refer to the following sample code to complement the JavaScript functionality, to complete the writing of a JavaScript code
    • This task completes the function: the user can enter any content in the input box, after clicking the "Confirm Fill in" button, the user enters the content to appear in "you entered the value is" the text the right

<! DOCTYPE html>

<meta charset= "Utf-8" >

<title>ife JavaScript Task 01</title>

<body>

<label> Please enter Beijing Air quality today: <input id= "Aqi-input" type= "text" ></label>

<button id= "button" > Confirm Fill </button>

<div> The value you entered is: <span id= "Aqi-display" > Not yet entered </span></div>

<script type= "Text/javascript" >

(function() {

/*   

Write down the code below the comment

bind a click event to button buttons

In the event handler function

gets The value of the aqi-input input and displays it in aqi-display

*/

})();

</script>

</body>

Task considerations

    • While implementing simple functionality, learn about JavaScript basic syntax, events, and DOM knowledge
    • Please note that the code style is neat and elegant
    • The code contains the necessary comments
    • Can not consider the legitimacy of the input
    • We recommend that you do not use any third-party libraries, frameworks
    • The sample code is just examples, can be used directly, or it can be overridden entirely by itself

Online learning Resources

    • JavaScript Introductory article
    • MDN JavaScript
0 basic JavaScript Coding (a) Summary

1. onclick Events

The OnClick event occurs when a user taps an object.

Grammar:

In HTML:

< element onclick= "myFunction ()" >

In JavaScript

    • object. onclick = function () {myScript};
    • object. onclick = myFunction;
    • object. AddEventListener ("click", myScript);

2. Input Text Value Property

The Value property sets or returns the values in the text input box, which includes default values, user input values, or values set in script.

Grammar:

Returns the Value property:textobject. Value

Set the Value property:textobject. Value = text

Property value: Text: Represents the value of the text field.

Return value: A string that represents the value of the text field.

3. DOM InnerHTML Properties

The innerHTML property is used to get and modify all tags and content within a specified element, which is a string that contains both the contents of the element (as well as the child elements), and the element content is displayed in the original HTML code, such as "<p>some text</p>"

Grammar:

Returns the InnerHTML property:htmlelementobject. InnerHTML

Set InnerHTML property:htmlelementobject. InnerHTML = text

Property value: Text: Represents the HTML content of an element.

Return value: A string that represents the HTML text.

4. Node.innertext

The content that represents the node content and its descendants, unlike innerHTML, does not contain HTML tags.

5. DOM textcontent Properties

The Textcontent property is used to set or return the textual content of a node and its internal nodes. Setting the Textcontent property on a node deletes all its child nodes and replaces it with a text node with the given value.

Grammar:

Returns the text content of thenode: node. textcontent

Set the text content of thenode: node. textcontent = text

Property Value: text : String Type: Represents the text content of the specified node.

Return value: A string that represents the node and child node text.

6. textcontent difference from innertext

(1) Textcontent will get content for all elements, including <script> and <style> elements. InnerText not.

(2) InnerText does not acquire the content of the hidden element, and Textcontent will.

(3) InnerText will trigger Reflow, and textcontent will not.

(4) InnerText return value will be formatted, and textcontent will not.

7. textcontent difference from innerHTML

InnerHTML returns HTML text, which is better when you modify the text in an element, using Textcontent.

8. Job submitted

Code Address: https://github.com/Nunawading2016/2017-IFE-Baidu/blob/master/task2-1

Demo Address: http://htmlpreview.github.io/?https://github.com/Nunawading2016/2017-IFE-Baidu/blob/master/task2-1/index.html

0 Basic JavaScript encoding (i)

Related Article

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.