Task 13: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>
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

Task Completion and Summary:

To be honest, at present still is the JS small white, from this chapter task begins, except has the explanation is oneself to do, other is analyzes others ' wonderful code and the thought. First of all, look at the first man's ideas and implementation of the way:

This is a very clever package of a variable, so that the code is very concise, this is a big bright spot. The next highlight is the addition of a carriage return event, which takes into account most of the situation, including the range of values, types, and the conversion of possible decimals using the parseint method.

Code Demo Address: https://cruxf.github.io/BaiduTest/test13.html

Code Address: https://github.com/CruxF/BaiduTest/blob/master/test13.html

Another way to make the hole open is this:

The button is initially bound to a click event, then the value is judged by the trinocular operator and number method to output the result. The code is very concise, the idea is very good, but the flaw is also very meditation, that is, the range of negative and actual values is not taken into account.

Task 13: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.