简体   繁体   English

引导程序模式中的href && href.replace(/.*(?=#[^ \\ s] + $)/,'')注释为“ strip for ie7”,该行对ie7有什么作用?

[英]href && href.replace(/.*(?=#[^\s]+$)/, '') in bootstrap modal commented as “strip for ie7”, what does this line do for ie7?

I am just wondering what goods does this line do for IE7? 我只是想知道这条线对IE7有什么作用? This code snippet is from bootstrap modal source code. 此代码段来自引导程序模态源代码。

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

Until IE8 there was a "feature" in IE's implementation of getAttribute() 在IE8之前,IE的getAttribute()实现中都有一个“功能”

If you have an <a> tag like this 如果您有这样的<a>标签

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

and you are using element.getAttribute('href') IE7 returns the absolute path - http://example.com/index.html#anchor while other browsers just returns #anchor . 并且您正在使用element.getAttribute('href') IE7返回绝对路径#anchor : http://example.com/index.html#anchor而其他浏览器仅返回#anchor

The regex in bootstrap takes care of this - it removes anything before # . 引导程序中的正则表达式会处理此问题-它会删除#之前的所有内容。


Update. 更新。 See also this very old question in SO (oct 2009!) -> Wrong extraction of .attr(“href”) in IE7 vs all other browsers? 另请参见SO中的一个非常老的问题(2009年10月!)-> 与其他所有浏览器相比,IE7中错误提取.attr(“ href”)吗? with various suggestions of how to solve the problem. 关于如何解决问题的各种建议。 Twitter Bootstraps solution is far better, in my opinion. 我认为,Twitter Bootstraps解决方案要好得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM