To do the project, encountered a very tangled problem, is to get the two value comparison, but there is a single number than the two-digit large case.
At first, I thought it was wrong to write, checked several times, with IE tune down, realize that it should be the wrong comparison method. Just think of the past has also encountered this situation, the reason is that JS default comparison string, first compare two first characters, the same and then compare the second one, and so on.
Therefore, for the comparison of numbers, first to convert to a number, and then compare, there will be no error.
JS in the numerical comparison, as follows:
var id=document.pageaction.pagenow.value;-->4var count=document.pageaction.count.value;-- >30 alert (id>count); // The result is true
Alert result is true because the JS default comparison string, first compares two first characters, the same compares the second one, and so on
How to resolve:
Use parseint (ID) for integer conversions:
Alert (parseint (ID) >parseint (count)); // The result is Falsealert (Eval_r (ID) >eval_r (count)); // The eval () function is used to calculate a code string without referencing any particular object.
Compare number sizes in JavaScript