为什么警告AnchorElement(< a>)会警告href属性?
问题描述:
<a href="url">A link</a>
$.each($('a'), function(index,value){
alert (value)
});
它会发出警告: url
。
为什么会这样?
It will alert : url
.
Why this happens?
答
这是因为 toString()$ c $锚的c>给出了URL。
It's because the toString()
of the anchor gives the URL.
alert
调用 toString()
对象的隐含性。因此,当您提醒数组时:
alert
calls toString()
implicity on objects. so when you alert an array like:
[1,2,3,4,5,6]
警告它会给你:
"1,2,3,4,5,6"
因为toString( )数组
是用逗号分隔的元素。
Because the toString() of array
is the elements separated by a comma.
如果在调试时遇到此问题,则应使用 console.log()
而不是 alert()
If you encounter this problem while debugging, you should use console.log()
instead of alert()