href && href.replace(/.*(?=#[^\s]+$)/, '') in bootstrap modal commented as "strip for ie7", 这条线对ie7有什么作用?
href && href.replace(/.*(?=#[^\s]+$)/, '') in bootstrap modal commented as "strip for ie7", what does this line do for ie7?
我就想知道这行对IE7有什么用?此代码片段来自 bootstrap 模态源代码。
var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
直到 IE8 在 IE 的 getAttribute()
实现中有一个 "feature"
如果您有这样的 <a>
标签
<a href="#anchor">link</a>
并且您正在使用 element.getAttribute('href')
IE7 returns 绝对路径 - http://example.com/index.html#anchor
而其他浏览器只是 returns #anchor
。
bootstrap 中的正则表达式会处理这个问题 - 它会删除 #
.
之前的所有内容
更新。另请参阅 SO(2009 年 10 月!)中的这个 very 旧问题 -> Wrong extraction of .attr(“href”) in IE7 vs all other browsers? 以及有关如何解决问题的各种建议。在我看来,Twitter Bootstraps 解决方案要好得多。
我就想知道这行对IE7有什么用?此代码片段来自 bootstrap 模态源代码。
var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
直到 IE8 在 IE 的 getAttribute()
如果您有这样的 <a>
标签
<a href="#anchor">link</a>
并且您正在使用 element.getAttribute('href')
IE7 returns 绝对路径 - http://example.com/index.html#anchor
而其他浏览器只是 returns #anchor
。
bootstrap 中的正则表达式会处理这个问题 - 它会删除 #
.
更新。另请参阅 SO(2009 年 10 月!)中的这个 very 旧问题 -> Wrong extraction of .attr(“href”) in IE7 vs all other browsers? 以及有关如何解决问题的各种建议。在我看来,Twitter Bootstraps 解决方案要好得多。