简体   繁体   English

HTML锚点在IE9中无法正常工作

[英]Html anchors not working correctly in IE9

I have this dirty html that is currently used in my company, the issue is that the hyperlinks or anchors work in IE8, but not in IE9 any reason why this is not working in IE9?. 我的公司目前使用的是这个肮脏的html,问题是超链接或锚点在IE8中起作用,但在IE9中却不起作用,为什么在IE9中不起作用? Basically its just clicking on the link and then it should focus on the id, like when i click on specialties I see the url changing like this 基本上,它只是单击链接,然后应将焦点放在id上,例如当我单击专业时,我看到URL会像这样变化

file:///C:/Users/TestUser/Desktop/test.html#c3

Now in IE8 when i do the click it correctly goes to that section #c3 现在在IE8中,当我点击时,它会正确转到该部分#c3

Well this code does not work either in IE9 那么这段代码在IE9中也不起作用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<p id="titleC"><a href="#c3">Specialty</a></p>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<p id="#c3">Did it work?</p>
<p>Then your code is wrong</p>
</body>

Thehash is the problem: 哈希是问题所在:

<p id="c3">Did it work?</p>

(without the hash) should work. (没有哈希)应该可以。

Maybe you should use 也许你应该使用

<a id="c3" name="c3">Did it work?</a>

for compatibility reasons. 出于兼容性原因。

All you attributes need to but surrounded by single or double quotation marks. 您的所有属性都需要但必须用单引号或双引号引起来。 For one on the many incorrect lines in the html 对于html中许多不正确的行之一

<P id=#titleQ class=style1>

Should be 应该

<P id="#titleQ" class="style1">

Run into the same issue and from my experience, on IE9 the anchor tag <a> does not recognise id or name on other elements other than another <a> tag, so as a workaround, you probably want to add a dummy empty <a> tag link above the element you want to link to, like so: 遇到相同的问题,根据我的经验,在IE9上,锚标记<a>无法识别其他<a>标记以外的其他元素的ID或名称,因此,一种变通方法是,您可能想添加一个空的<a>要链接到的元素上方的标签链接,如下所示:

<body>
    <p id="titleC"><a href="#c3">Specialty</a></p>
    ...
    <a id="c3" name="c3"></a>
    <p>Did it work?</p>
    <p>Then your code is wrong</p>
</body>

尝试添加此元标记,也许可以解决该问题:

<meta http-equiv="X-UA-Compatible" value="IE=8">

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

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