在jQuery中标准化attr('href')返回 [英] Standardizing attr('href') returns in jQuery
问题描述
假设我在wwww.example.com/foo.html
Suppose I have a link <a href='?action=run'>
, on a webpage wwww.example.com/foo.html
在Firefox中,attr('href')
返回'?action = run'
In Firefox, attr('href')
returns '?action=run'
在IE中,它返回' http://www.example.com/foo .html?action = run '
- 使用attr('href')时,通常预期会发生哪种行为(是否有任何标准?)
- 是否有可能使IE也返回'?action = run'吗?
推荐答案
jQuery 应该已经为您处理了此问题,在此处进行快速测试.
jQuery should be handling this for you already, you can see it in the source here, and in a quick test here.
如果浏览器尚未通过jQuery进行规范化,请通过 $.support.hrefNormalized
进行检查(在IE中为false),它用于 href
, src
和style
属性.
jQuery normalizes it if the browser doesn't already, checked via $.support.hrefNormalized
(false in IE), it does this for href
, src
and style
attributes.
是否有可能您使用的是旧版jQuery,但没有执行此操作?如果是这样,升级是您的答案.另外,请确保您确实在使用.attr('href')
进行标准化,而不是直接使用.href
.
Is it possible you're using a very old version of jQuery that didn't do this? If so upgrading is your answer. Also be sure that you are indeed using .attr('href')
to get the normalization, and not .href
directly.
这篇关于在jQuery中标准化attr('href')返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!