Preface:
Before making a judgment, we must first know that the variable defined by var in js is a string by default. If you simply compare the string, an error will occur and you need to convert it into an int type for comparison.
[ Note : 110 and 18 are 18 in the program you write, because these two numbers are strings, and after 1 and 1 are equal, 1 and 8 are of course 8, so 18 is large. You convert to INT type before comparison. if(parseInt(num2)>parseInt(num1)) 】
Error instance:
<script> function check() { var num1=document.form1.num1.value; var num2=document.form1.num2.value; if(num2>num1) <!-Error writing--> { alert('num2 > num1!'); return false; } return true; } </script>Correct example:
<script> function check() { var num1=document.form1.num1.value; var num2=document.form1.num2.value; if(parseInt(num2)>parseInt(num1)) <!-Correct writing (convert to INT) --> { alert('num2 > num1!'); return false; } return true; } </script>The above uses two examples of correct and wrong to demonstrate how to judge the size of two numbers, so don’t mess it up.