控制台.log() 正在打印同一变量的两个不同值

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

本文关键字:两个 变量 打印 控制台 log      更新时间:2023-09-26

我正在运行一个代码,我与您分享,这很简单,在两个不同的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>

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

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