简体   繁体   English

在jQuery中标准化attr('href')返回

[英]Standardizing attr('href') returns in jQuery

Suppose I have a link <a href='?action=run'> , on a webpage wwww.example.com/foo.html 假设我在<a href='?action=run'>网页上有一个链接<a href='?action=run'> href='?action=run'>

In Firefox, attr('href') returns '?action=run' 在Firefox中, attr('href')返回'?action = run'

In IE, it returns ' http://www.example.com/foo.html?action=run ' 在IE中,它返回' http://www.example.com/foo.html?action=run '

  1. When using attr('href'), usually which behaviour is expected (are there any standards?) 使用attr('href')时,通常预期会发生哪种行为(是否有任何标准?)
  2. Is it possible to make IE returns just '?action=run' too? 是否有可能使IE也返回“?action = run”?

jQuery should be handling this for you already, you can see it in the source here , and in a quick test here . jQuery 应该已经为您解决了这一问题, 您可以在此处的源代码中进行查看 ,并在此处进行快速测试

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 . 如果浏览器尚未通过$.support.hrefNormalized (在IE中$.support.hrefNormalized false)检查,则jQuery对其进行归一化,它对hrefsrcstyle属性执行此操作

Is it possible you're using a very old version of jQuery that didn't do this? 是否有可能您使用的是旧版jQuery而不执行此操作? If so upgrading is your answer. 如果是这样,升级是您的答案。 Also be sure that you are indeed using .attr('href') to get the normalization, and not .href directly. 另外,请确保您确实在使用.attr('href')进行规范化,而不是直接使用.href

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

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