奇怪的问题 本帖最后由 gaozhi0 于 2009-12-28 11:22:07 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(clientip4<=ipn[3]){ alert("yes too too too!");}这一行判断应该执行的,却没有执行,因为clientip4<=ipn[3]返回false,这两个变量是我前面已经赋值了的 var a="35",b="255";alert(a<b);alert((a-0)<(b-0));//-0转化 为int 这个可以,或者加上parseInt() if(parseInt(clientip3)<=parseInt(ipn[2])){ alert("yes too too"); alert("clientip4:"+clientip4+" ipn[3]:"+ipn[3]); alert(clientip4<=ipn[3]); if(clientip4<=ipn[3]){ alert("yes too too too!"); } } //clientip4=35,ipn[3]=255,但是下面的对话框弹出的竟然是false,if判断也没执行。被你注释掉了改为clientip4=35; ipn[3]=255;试下 应该是其他地方的问题,调用。测试没问题啊,在数组比较时最好加上parseInt()<script>var test=function(){ var clientip1=35;var ipn=new Array(); ipn[0]=50; ipn[1]=100; ipn[2]=200; ipn[3]=255; if(clientip1<=parseInt(ipn[0])){ alert("yes") if(clientip1<=parseInt(ipn[1])){ alert("yes too"); if(clientip1<=parseInt(ipn[2])){ alert("yes too too"); alert("clientip4:"+clientip1+" ipn[3]:"+parseInt(ipn[3])); //clientip4=35,ipn[3]=255,但是下面的对话框弹出的竟然是false,if判断也没执行。 alert(clientip1<=parseInt(ipn[3])); if(clientip1<=parseInt(ipn[3])){ alert("yes too too too!"); } } } }}();</script> //clientip4=35,ipn[3]=255,但是下面的对话框弹出的竟然是false,if判断也没执行这一行是我写给你们看的,不是程序里面的代码,是我的错,写在这个位置你们都以为是代码问题已经解决,我的疑问是为什么我其他的判断也是这样写:if(clientip1<=ipn[0])。为什么就只有这一个判断有问题呢,想不通。 也许你其他地方判断时:clientip1 和ipn[0] 已经转化为 数值类型了,而这个函数中是 字符,而且你说的"其他地方判断时没问题" 可能也有问题,因为clientip1 和ipn[0]假如用的的是字符,也是可以判断例如:<script> function b(){ var a = "A"; var b = "3"; if(a>b){ alert("true"); } }</script><input type = "button" value = "dddd" onclick= "b();"/></script>结果是“true” 请教怎么用cookie记录最近浏览过的商品?或请高人帮我修改下这段代码,谢谢。 window.frames[""].document.getElementById("")的问题 JS提交内嵌框页面的表单 网上复制过来的一段代码,就是搞不懂那儿报错. 如何给MediaPlayer增加播放列表? 这个是不是有点战呢? 请问个表单限制问题! 在netscape6里如何屏蔽空格 树型菜单的问题 50分求解!如何使层显示在最前面? 我用javascript调用outlook发邮件,可是表单的内容在outlook中怎么换行??? 请问如何阻止js事件触发 谢谢~~ 帮我毕业~~~
alert("yes too too too!");
}
这一行判断应该执行的,却没有执行,因为clientip4<=ipn[3]返回false,这两个变量是我前面已经赋值了的
var a="35",b="255";
alert(a<b);
alert((a-0)<(b-0));//-0转化 为int
或者加上parseInt()
if(parseInt(clientip3)<=parseInt(ipn[2])){
alert("yes too too");
alert("clientip4:"+clientip4+" ipn[3]:"+ipn[3]);
alert(clientip4<=ipn[3]);
if(clientip4<=ipn[3]){
alert("yes too too too!");
}
}
被你注释掉了
改为clientip4=35;
ipn[3]=255;
试下
var test=function(){
var clientip1=35;var ipn=new Array();
ipn[0]=50;
ipn[1]=100;
ipn[2]=200;
ipn[3]=255;
if(clientip1<=parseInt(ipn[0])){
alert("yes")
if(clientip1<=parseInt(ipn[1])){
alert("yes too");
if(clientip1<=parseInt(ipn[2])){
alert("yes too too");
alert("clientip4:"+clientip1+" ipn[3]:"+parseInt(ipn[3]));
//clientip4=35,ipn[3]=255,但是下面的对话框弹出的竟然是false,if判断也没执行。
alert(clientip1<=parseInt(ipn[3]));
if(clientip1<=parseInt(ipn[3])){
alert("yes too too too!");
}
}
}
}
}();</script>
这一行是我写给你们看的,不是程序里面的代码,是我的错,写在这个位置你们都以为是代码
问题已经解决,我的疑问是为什么我其他的判断也是这样写:if(clientip1<=ipn[0])。
为什么就只有这一个判断有问题呢,想不通。
而且你说的"其他地方判断时没问题" 可能也有问题,因为clientip1 和ipn[0]假如用的的是字符,也是可以判断
例如:
<script>
function b(){
var a = "A";
var b = "3";
if(a>b){
alert("true");
}
}
</script>
<input type = "button" value = "dddd" onclick= "b();"/>
</script>
结果是“true”