问题与比较JavaScript中的两个数字 [英] issue with comparing two numbers in javascript
本文介绍了问题与比较JavaScript中的两个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的html代码如下所示:
< html>
< SCRIPT type =text / javascriptlanguage =JavaScript>
函数fun()
{
var l = document.test.low.value;
var h = document.test.high.value;
alert(l);
alert(h);
if(l> h){
alert(低于高位低位为 - + l +高位为 - + h);
}
}
< / SCRIPT>
< body>
< form name =test>
< input type =textsize =11id =low/>
< input type =textsize =11id =high/>
< input type =buttonvalue =sssonClick =fun()/>
< / form>
< / body>
< / html>
当我比较这两个使用低值的值是12而高值是112时不起作用。
喜欢22和122,33和133等....
我使用的是IE浏览器版本8.请帮助。
解决方案
试试这样: - $ / b>
if(parseInt (l,10)> parseInt(h,10))
if(parseFloat(l,10)> parseFloat(h,10))
$ c $ ($)
$ p
$ p $ Number()
my html code is like:
<html>
<SCRIPT type="text/javascript" language="JavaScript">
function fun()
{
var l = document.test.low.value;
var h = document.test.high.value;
alert(l);
alert(h);
if(l >h){
alert("low greater than high low is -"+l+"high is -"+h);
}
}
</SCRIPT>
<body>
<form name="test">
<input type="text" size="11" id="low" />
<input type="text" size="11" id="high" />
<input type="button" value="sss" onClick="fun()"/>
</form>
</body>
</html>
when i compare this two values using low is 12 and high is 112 is not working. like 22 and 122, 33 and 133 etc....
I am using IE browser version 8. please help.
解决方案
try like this :-
if(parseInt(l,10)>parseInt(h,10))
or for floating Numbers you can use
if(parseFloat(l,10)>parseFloat(h,10))
or simply use
Number()
这篇关于问题与比较JavaScript中的两个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文