Under normal circumstances:
if (2 >)
{
alert ("Incorrect!");
}
This comparison will not be the desired result: it is equivalent to 2 >1, comparing the first bit of 10 out.
Workaround:
if (eval (2) > eval)
{
alert ("Incorrect!");
}
The eval () function is used to compute a code string without referencing any particular object.
<script>
function Check ()
{
var num1=document.form1.num1.value;
var num2=document.form1.num2.value;
if (NUM2>NUM1) <!-error notation-->
{
alert (' num2 > num1! ');
return false;
}
return true;
}
</script>
<script>
function Check ()
{
var num1= Document.form1.num1.value;
var num2=document.form1.num2.value;
if (parseint (num2) >parseint (NUM1)) <!-correct notation (converted to int)-->
{
alert (' num2 > num1! ');
return false;
}
return true;
}
</script>
EG:
110 and 18 are 18 large in the program you're writing, because
These two numbers are strings, and 1 and 1 are equal after 1 and 8, of course 8, so 18 large
You convert to int before comparing
if (parseint (num2) >parseint (NUM1))
The above JS comparison of two numerical size example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.