问题
I have a single-page HTML5 website with navigation that should send the user to that section. Works great in all browsers except IE8, which doesn't do anything. Dummied version of what I have:
<a href="#about">About</a>
<a href="#work">Work</a>
<a href="#services">Services</a>
<a href="#process">Process</a>
<a href="#contact">Contact</a>
<section id="about">
...
</section>
<section id="work">
...
</section>
<section id="services">
...
</section>
<section id="process">
...
</section>
<section id="contact">
...
</section>
Did a search with no luck. Saw some solutions about adding non-breaking spaces or some text to the targeted section/div, but that didn't work. Stumped.
回答1:
Firstly, use name
rather than id
(or possibly name
as well as id
, if you also need to use the id for something else).
<section name="work">
Secondly, IE8 and earlier doesn't support the new HTML5 elements like <section>
.
In order to fix this, you need to use a hack like the html5shiv. (or use Modernizr which has html5shiv built in).
Both html5shiv and Modernizr are Javascript based. If you don't want to or can't use them for whatever reason, then you'll have to switch to using HTML tags that IE8 does support, like <div>
.
Hope that helps.
回答2:
At first, Internet Explorer 8 does not support HTML5, so it doesn't understand the section tag.
The second point is, that normally the name-attribute is used to create anchors on sites.
You can try adding name-attributes to your section tags, but I think IE won't understand this too, so you would have to use divs or do a workaround with some javascript.
来源:https://stackoverflow.com/questions/15443625/same-page-anchor-links-to-section-ids-not-working-in-ie8