Javascript to achieve equality of values in the addition of squares _ javascript skills

Source: Internet
Author: User
This article mainly introduces the relevant information about how to use javascript to achieve the same sum of values of the nine squares. For more information about how to use javascript to implement the nine squares, see the examples in this article, the details are as follows:

Implementation ideas:
1. the input value of each grid must be a number;

2. the input values cannot be repeated;

3. the input value cannot be less than 1 or greater than 9;

4. The value cannot be blank;

5. a total of eight values are added, which are horizontal, vertical, and diagonal. The details are as follows:

Explanation:

Marked by the serial number of each grid:

Values: 0-2, 3-4, 6-8;

Vertical values: [, 6], [, 7], [, 8];

Two diagonal values: [0, 4, 8], [2, 4, 6]

Implementation process:
Just like the image above, click submit to start judgment.

1. Layout
Html section:

Submit

Css part: implemented by attributes in css3.

*{margin:0;padding:0;outline: none;}html,body{  height: 100%;  display: flex;  justify-content: center;  align-items: center;}.box{  position: relative;  width: 250px;  margin:0 auto;}input{  text-align: center;  font: 40px/60px 'Microsoft YaHei';  width: 30%;  float:left;  box-sizing:border-box}button{  position: absolute;  bottom:-30px;  left: 50%;  margin-left: -30px;  width: 40px;}

2. next we will focus on the js part.
I have already mentioned the js implementation method. here is the relevant code.

Var oBtn = document. getElementsByTagName ('Button ') [0], aInp = document. getElementsByTagName ('input'); function isNum () {var aTemp = []; // create a temporary function to store the numbers in the nine cells at a time for (I = 0; i9) {// Determine whether the value in the current input box is a number, less than 1, or greater than 9? Alert ('1. you can only enter 1-9 pure numbers; 2. cannot be blank; '); return false; // if any of the conditions is met, exit the function without going down} for (s = 0; s

1. when the input value is not a number, 9 or less than 0, or empty


2. when repeated numbers are input


3. when the input is correct

The above is all the content of this article, and I hope it will help you learn javascript programming.

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.