奇怪的问题 本帖最后由 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” js脚本会被搜索引擎执行并收录吗? 提取出来了VB的内容,劳驾大家帮我改成JS!多谢了! 郁闷。。。高手进,如何自定义执行元素定义的事件 正则表达式问题!? 文本框.当用户输入时,怎么限制只能输入两行. 在js中得到日期之间的差的程序简化及一些缺陷问题的请教,js高手请指点!! 页面刷新的问题 关于文件绝对路径 请教高手:怎样能实现用户点击“下载”后能实现下载后自动安装程序功能。 怎样获取当前光标所在位置的是textNodes(急急急急急急急在线等待) 请问如何阻止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”