为什么警告AnchorElement(< a>)会警告href属性? [英] Why alert AnchorElement (<a>) alerts the href attribute?
本文介绍了为什么警告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()
这篇关于为什么警告AnchorElement(< a>)会警告href属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文