Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果锚点还具有name属性,则Javascript-getElementById将失败_Javascript_Anchor_Getelementbyid - Fatal编程技术网

如果锚点还具有name属性,则Javascript-getElementById将失败

如果锚点还具有name属性,则Javascript-getElementById将失败,javascript,anchor,getelementbyid,Javascript,Anchor,Getelementbyid,我遇到了一个奇怪的失败。如果锚元素上同时有ID和NAME属性,document.getElementById就会失败。如果我删除了这个名字,它就会起作用。我在Firefox3.5(最新版本)中看到了这一点,但还没有检查其他浏览器 这是一个bug还是故意的?我从来没有听说过这样的bug,所以我试图复制它,但失败了。这表明你误诊了这个问题,或者至少没有提供足够的信息 我使用Firefox3.5和以下代码进行了测试 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML

我遇到了一个奇怪的失败。如果锚元素上同时有ID和NAME属性,document.getElementById就会失败。如果我删除了这个名字,它就会起作用。我在Firefox3.5(最新版本)中看到了这一点,但还没有检查其他浏览器


这是一个bug还是故意的?

我从来没有听说过这样的bug,所以我试图复制它,但失败了。这表明你误诊了这个问题,或者至少没有提供足够的信息

我使用Firefox3.5和以下代码进行了测试

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<title>Test of getElementById with named anchors</title>
<h1>Test of getElementById with named anchors</h1>

<h2><a name="one" id="one">First section</a></h2>
<p>The quick brown fox</p>

<h2><a name="two" id="second">Second section</a></h2>
<p>The quick brown fox</p>

<script type="text/javascript">    
if (document.getElementById('one')) {
        document.write("<p>First section found - id matches name<\/p>");
}

if (document.getElementById('second')) {
        document.write("<p>Second section found - id does not match name<\/p>");
}
</script>

使用命名锚测试getElementById
使用命名锚测试getElementById
第一节
敏捷的棕色狐狸

第二节 敏捷的棕色狐狸

if(document.getElementById('one')){ write(“找到的第一部分-id与名称匹配”); } if(document.getElementById('second')){ document.write(“找到第二节-id与名称不匹配”); }
我从来没有听说过这样的错误,所以我试图复制它,但失败了。这表明你误诊了这个问题,或者至少没有提供足够的信息

我使用Firefox3.5和以下代码进行了测试

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<title>Test of getElementById with named anchors</title>
<h1>Test of getElementById with named anchors</h1>

<h2><a name="one" id="one">First section</a></h2>
<p>The quick brown fox</p>

<h2><a name="two" id="second">Second section</a></h2>
<p>The quick brown fox</p>

<script type="text/javascript">    
if (document.getElementById('one')) {
        document.write("<p>First section found - id matches name<\/p>");
}

if (document.getElementById('second')) {
        document.write("<p>Second section found - id does not match name<\/p>");
}
</script>

使用命名锚测试getElementById
使用命名锚测试getElementById
第一节
敏捷的棕色狐狸

第二节 敏捷的棕色狐狸

if(document.getElementById('one')){ write(“找到的第一部分-id与名称匹配”); } if(document.getElementById('second')){ document.write(“找到第二节-id与名称不匹配”); }
无法复制。几乎可以肯定的是,您同时做了一些其他更改。可能是删除的名称标记与另一个名称标记之间发生了冲突?我唯一一次看到类似的情况是在IE中-它不区分名称/id属性,因此getElementById返回在发生冲突时您并不总是期望的内容。的值是多少冲突的
name
attribute?在我的例子中,我这样做是为了一个Tweet按钮。原来API正在将我的锚更改为iframe。无法复制。几乎可以肯定的是,您同时做了一些其他更改。可能是删除的名称标记与另一个名称标记之间发生了冲突?我唯一一次看到类似的情况是在IE中-它不区分名称/id属性,因此getElementById返回在发生冲突时您并不总是期望的内容。的值是多少冲突的
name
attribute?在我的例子中,我这样做是为了一个Tweet按钮。结果是API将我的锚更改为iframe。同样,我无法在我的3.5.2 firefox上复制它\谢谢你们的测试。我现在不知道是什么原因造成的,但如果我将来有时间,我会调查的。我想知道这是我的代码,还是一个我无法完全描述的奇怪的边缘情况。同样,我无法在我的3.5.2 firefox上重现它\谢谢你们的测试。我现在不知道是什么原因造成的,但如果我将来有时间,我会调查的。我想知道这是我的代码,还是一个我无法完全描述的奇怪的边缘情况。