zoukankan      html  css  js  c++  java
  • 个性A标签

    问题:

    前段时间,小琳同学问我A标签为啥alert出来的是它的href?

    示例:

    先来两个标签比较一下。

    <a id="a" href="http://www.baidu.com">baidu.com</a>
    <span id="b">baidu.com</span>

    再敲点代码比较一下。

    alert(a);              // "http://www.baidu.com/"        不是常见的啥啥对象
    alert(b);              // "[object HTMLSpanElement]"     正常的啥啥对象
    alert(a.id);           // "a"                            能取到标签的属性
    alert(a.href);         // "http://www.baidu.com/"
    alert(a==a.href);      // true                           表示结果相同
    alert(a===a.href);     // false                          表示本质不同
    alert(a.toString());   // "http://www.baidu.com/"        A标签toString返回的是它的href

    可以发现,问题出在A标签的toString上,再比较一下。

    alert(a.toString==b.toString);                // false
    alert(b.toString==document.body.toString);    // true

    这表示A标签的toString函数不是继承来的,而是被重新了,它返回自己的href值。

    收获:

    个性标签,还有没有了?

  • 相关阅读:
    python_6
    python_day4
    python_day3
    python_day2
    python
    python入门
    jQuery之前端国际化jQuery.i18n.properties
    转载!网页中插入百度地图
    jQuery.validate 中文API
    Web移动端Fixed布局的解决方案
  • 原文地址:https://www.cnblogs.com/ccforeverd/p/3898369.html
Copyright © 2011-2022 走看看