繁体   English   中英

Console.log()打印相同变量的两个不同值

[英]Console.log() is printing two different values of same variable

我正在运行一个代码,并与您共享它,这非常简单,对于两个不同的console.log()命令,它返回两个不同的结果。 在这里, ".filter_me"类分配给了锚点,

$(".filter_me").each(
    function(index,value)
    {    
        console.log(index+" is index and "+value+" is value.");
        //output of above line is "0 is index and "http://www.ex.com/2 
        //is value"{for first anchor,http://www.ex.com/ is base url and
        //2 is value of href of first anchor}
        console.log(value);
        //output of above line is <a href="2" class="filter_me">clk</a>
    });

那为什么在第一种情况下

value = http://www.ex.com/2

在第二种情况下

value = <a href="2" class="filter_me">clk</a>

由于您的日志中还有其他字符串,因此第一个值将转换为字符串。

第二个值是对象,因为它是日志中的唯一元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM