This article mainly share with you how jquery determines the size of two values, mainly in the form of code and we share, hope to help everyone.
$a = ten; $b = 2;if ($a < $b) {echo "B is greater than a";} Else{echo "A greater than B"};
In JS, VAR defines variables and generates strings.
var a = 10;var B = 2;if (A < b) {alert ("error");} Else{alert ("normal");};
The running result is normal; 10 is less than 2 normal. Obviously, this is not the result we want. Why? Because Two is a string, take the first bit of a 1, take the first bit of B 2; Obviously, 2 is greater than 1. Then return to normal.
Workaround:
One, eval () function
if (eval (a) <eval (b)) {//Logical business} The eval () function is used to calculate a code string without referencing any particular object.
Second, parseint () function
The IF (parseint (a) <parseint (b)) {//Logical business} parseint () function is used in converting to int.
Multiplication operation (disguised conversion type) (primary school sports teacher once said: Both sides multiplied by the same number, the equation does not change)
if (a *10 < b * 10) {//Logic business}