1、如何把boolean值‘ture’赋给数组中的string[1]
2、此时,string[1]=="ture"  是否成立
3、如果不成立,string[1]和等价。1、
var a=new Array();
a[0]=true2、是

解决方案 »

  1.   

    但是为什么这段代码运行后弹出:no
    <body>
    <input type="button" value="button" onclick="b()">
    </body>
    <script> 
    function b(){
    var a=new Array();
    a[0]="ture";
    if(a[0]=="true")
    {
    alert("yes");
    }
    else 
    {
    alert("no");
    }
    }
    </script>
      

  2.   

    “true”写错了,不过这样会以字符串比较
      

  3.   

    具体可以查看
    http://community.csdn.net/Expert/topic/5066/5066634.xml?temp=.8160974
      

  4.   

    1、如何把boolean值‘ture’赋给数组中的string[1]
    解:加了引号(不管是单引还是双引)都已经是string 了2、此时,string[1]=="true" 是否成立
    解:如果前面对string[1]的值赋了值的话是可以的,也就是成立的
    3、如果不成立,string[1]和等价。
    解:是成立的还有就是在js 中变量声明的时候是没有类型的,
    只在被赋值的时候才给予类型的.true is not ture
      

  5.   

    但是我通过程序测了一下,发现boolean型true和字符串型"true"不等,如下:
    <body>
    <input type="button" value="boolean and string" onclick="b()">
    </body>
    <script> 
    function b(){
    alert("这是一个测试boolean值true和字符串型\"true\"是否相等的程序")
    var a=new Array();a[0]=true;
    if(a[0]){
    alert("a[0]是布尔型 :a[0]=true");
    }a[1]="true";
    if(a[1]=="true"){
    alert("a[1]是字符串:a[1]=\"true\"")
    }
    if(a[0]==a[1])
    {
    alert("a[0]和a[1]相等:a[0]==a[1]成立,即boolean值true和字符串型\"true\"相等。");
    }
    else 
    {
    alert("a[0]和a[1]不等:a[0]==a[1]不成立,即boolean值true和字符串型\"true\"不等。");
    }}
    </script>
      

  6.   

    1.string[1] = 'true';
    2.是成立的,只不过是字符串的比较.
    3.如果string[0] = true,而string[1]='true';string[0]与string[1]两者比较是不相等的.
    因为一个是Boolean,一个是string.
      

  7.   

    使用 toString()后再比较就可以了.