JS compares the size instances of two values. Generally:
If (2> 10) {alert ("Incorrect! ");}
This comparison will not be the desired result: it is equivalent to 2> 1, and the first of 10 is compared.
Solution:
If (eval (2)> eval (10) {alert ("Incorrect! ");}
The eval () function is used to calculate the code string without referencing any specific object.
Script function check () {var num1 = document. form1.num1. value; var num2 = document. form1.num2. value; if (num2> num1)
{Alert ('num2> num1! '); Return false;} return true;} script function check () {var num1 = document. form1.num1. value; var num2 = document. form1.num2. value; if (parseInt (num2)> parseInt (num1 ))
{Alert ('num2> num1! '); Return false;} return true;} script
EG:
110 and 18 are 18 of the programs you write, because
These two numbers are both strings, and 1 and 1 are equal to 1 and 8, of course 8, so 18 is big.
Before comparison, convert the data to the INT type before comparison.
If (parseInt (num2)> parseInt (num1 ))