【问题标题】:href && href.replace(/.*(?=#[^\s]+$)/, '') in bootstrap modal commented as "strip for ie7", what does this line do for ie7?引导模式中的 href && href.replace(/.*(?=#[^\s]+$)/, '') 注释为“ie7 的条带”,这条线对 ie7 有什么作用?
【发布时间】:2015-12-14 07:31:40
【问题描述】:

我只是想知道这条线对IE7有什么作用?此代码 sn-p 来自 bootstrap modal 源代码。

var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7

【问题讨论】:

    标签: javascript twitter-bootstrap modal-dialog


    【解决方案1】:

    在 IE8 之前,IE 的 getAttribute() 实现中有一个“功能”

    如果你有这样的<a> 标签

    <a href="#anchor">link</a>
    

    而您正在使用element.getAttribute('href') IE7 返回绝对路径-http://example.com/index.html#anchor 而其他浏览器只返回#anchor

    引导程序中的正则表达式会处理这个问题 - 它会删除 # 之前的所有内容。


    更新。另请参阅 SO(2009 年 10 月!)-> Wrong extraction of .attr(“href”) in IE7 vs all other browsers? 中的这个非常老问题,并提供有关如何解决问题的各种建议。在我看来,Twitter Bootstraps 解决方案要好得多。

    【讨论】:

      猜你喜欢
      • 2012-01-25
      • 1970-01-01
      • 2012-08-04
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多