JavaScript问题原因 [英] JavaScript Problem Reason

查看:103
本文介绍了JavaScript问题原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JS中遇到问题,我有两个变量a和b
都具有类似
的值
a =``1716e362-5afe-4c80-9fff-880aaf109638''

b =''1716e362-5afe-4c80-9fff-880aaf109638''

我已经应用了类似
的条件

if(a== b)
{
//do some thing
}



出现的问题是if条件出现为假

我也尝试过===但它仍然显示为假:(

谁能告诉我原因是什么?

a和b的值相同

解决方案

它必须正确运行,像
一样检查

<script type="text/javascript">

var a = ''1716e362-5afe-4c80-9fff-880aaf109638'';
var b = ''1716e362-5afe-4c80-9fff-880aaf109638'';
if(a==b)
{
 alert("true");
}
else
{
 alert("false");
}

</script>



如果警报为真,则警报为假

希望对您有所帮助.尝试使用Javascript调试器(Internet Explorer中为F12,Chrome中为Ctrl-Shift-I或Firefox使用Firebug),然后在"if"语句中添加一个断点.然后,您应该可以检查a和b的值.


您还可以执行以下操作,

 <  脚本   类型  ="    语言  ="  javascript" <  /script  >  


i am having a problem in JS,i have two variables a and b
both have values like

a= ''1716e362-5afe-4c80-9fff-880aaf109638''

b= ''1716e362-5afe-4c80-9fff-880aaf109638''

I have applied a condition like

if(a== b)
{
//do some thing
}



The problem is arising is that the if condition is appearing false

I also tried === but its still showing false :(

Can any one tell me whats the reason??

a and b values are same

解决方案

It must function correctly , Check it like

<script type="text/javascript">

var a = ''1716e362-5afe-4c80-9fff-880aaf109638'';
var b = ''1716e362-5afe-4c80-9fff-880aaf109638'';
if(a==b)
{
 alert("true");
}
else
{
 alert("false");
}

</script>



If alerts true than same else alerts false

Hope it helps


My guess is that something is changing a or b (or both). Try using a Javascript debugger (F12 in Internet Explorer, Ctrl-Shift-I in Chrome or use Firebug for Firefox) and add a breakpoint at your "if" statement. You should then be able to examine the values of a and b.


You can also do the following,

<script type="text/javascript" language="javascript">
        var a = '1716e362-5afe-4c80-9fff-880aaf109638';
        var b = '1716e362-5afe-4c80-9fff-880aaf109638';
        if (parseInt(a) == parseInt(b)) {
            alert("Match");
        }
        else {
            alert("UnMatch");
        }
    </script>


这篇关于JavaScript问题原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆