Wrong extraction of .attr(“href”) in IE7 vs all ot

2020-01-24 09:47发布

Can it really be true that the attr("href") command for a link is handled very different in IE7 in comparison to all other browsers?

Let's say I have a page at http://example.com/page.html and I have this HTML:

<a href="#someAnchor" class="lnkTest">Link text</a>

and this jQuery:

var strHref = $(".lnkTest").attr("href");

Then in IE7 the value of the strHref variable will be "http://example.com/page.htm#someAnchor" but in other browsers it will be "#someAnchor".

I believe that the last mentioned case is the most correct one, so is it just a case of IE7 being a bad boy or is it a bug in jQuery?

7条回答
何必那么认真
2楼-- · 2020-01-24 10:11

another way is to just use a data attribute, instead of href

<a data-href="#anchor-0">example</a>

.

var href = $(this).attr('data-href');
查看更多
登录 后发表回答