>
运算符对我来说无效!
var message = document.getElementById("success");
message.innerHTML = startNumber + ">" + endNumber;
document.getElementById("mes").innerHTML = startNumber > endNumber;
input1:startNumber = 45,endNumber = 1
////// output1:45> 1 trueinput2:startNumber = 45,endNumber = 5
////////输出2:45> 5假
更新(我之前/之后的变量声明)谢谢:)
<!--Before-->
<form>
<input type="text" id="start_field" placeholder="start of">
<input type="text" id="end_field" placeholder="end at">
<input type="button" id="startbtn" value="Start">
</form>
var startPage =document.getElementById("start_field").value;
var endPage = document.getElementById("end_field").value;
<!--After-->
<form>
<input type="text" id="start_field" placeholder="start of">
<input type="text" id="end_field" placeholder="end at">
<input type="button" id="startbtn" value="Start">
</form>
var startPage =new Number(document.getElementById("start_field").value);
var endPage = new Number(document.getElementById("end_field").value);
答案 0 :(得分:5)
您正在处理字符串,而不是数字。 字符串&#34; 45&#34;不大于字符串&#34; 5&#34;。
如果您愿意,可以强制字符串进行数字解释:
document.getElementById("mes").innerHTML = +startNumber > +endNumber;
答案 1 :(得分:2)
试
document.getElementById("mes").innerHTML = parseInt(startNumber) > parseInt(endNumber);
强制进行数值比较(a.o.t.字符串比较)