Home  >  Article  >  Web Front-end  >  How to compare the size of two numbers in jquery

How to compare the size of two numbers in jquery

藏色散人
藏色散人Original
2020-11-27 10:34:493194browse

Jquery method to compare the size of two numbers: first create a new html file; then use the input tag to create two number input boxes; then use the button tag to create a button; finally use the val method to obtain the input numbers respectively. Then use the if statement to judge the size of the two numbers.

How to compare the size of two numbers in jquery

Recommended: "jquery tutorial"

The operating environment of this tutorial: Windows7 system, jquery1.10.0, this method Applicable to all brands of computers.

How jquery compares the size of two numbers:

Create a new html file, named test.html, to explain how to judge two numbers in JQuery size.

How to compare the size of two numbers in jquery

In the test.html file, use the input tag to create two number input boxes for testing.

How to compare the size of two numbers in jquery

In the test.html file, set an id attribute for each input tag, which is used to obtain the input element object below.

How to compare the size of two numbers in jquery

In the test.html file, use the button tag to create a button, bind the onclick click event to the button, and when the button is clicked, execute the bijiao() function.

How to compare the size of two numbers in jquery

In the js tag, create the bijiao() function. Within the function, obtain the input objects respectively through the id, use the val() method to obtain the input numbers respectively, and put Each obtained number is multiplied by 1, that is, converted to a numeric type. Finally, an if statement is used to judge the size of the two numbers.

How to compare the size of two numbers in jquery

Open the test.html file in the browser, enter the number in the input box, click the button to view the result.

How to compare the size of two numbers in jquery

The above is the detailed content of How to compare the size of two numbers in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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