Html 'id'属性在iframe中是否需要是唯一的?

Html 'id'属性在iframe中是否需要是唯一的?,html,iframe,Html,Iframe,例如,这是否有效 <!doctype html> <html> <head> <title>Some Iframes</title> </head> <body> <iframe id="frame1" src="/html/test-frame.html"></iframe> <iframe id="frame2" src="/html/te

例如,这是否有效

<!doctype html>
<html>

  <head>
    <title>Some Iframes</title>
  </head>

  <body>
    <iframe id="frame1" src="/html/test-frame.html"></iframe>
    <iframe id="frame2" src="/html/test-frame.html"></iframe>
  </body>

</html>

我希望能够对一组iFrame使用相同的html和相同的脚本。

这是可以接受和有效的。由于每个页面都是自包含的,因此有其各自的名称空间和DOM,因此在iframe中使用相同的ID并没有坏处,只要它在每个iframe文档中只出现一次。

iframe内部的每个页面都是完全自包含和唯一的

您可以有一个页面和4个iFrame,每个iFrame可以有一个名为
“#元素”


当然,您的代码是无效的,但是如果每个代码都加载了自己单独的HTML,那么这是完全可以接受的。

您是否确实在
iframe
元素中有内容?所有支持框架的浏览器都会忽略它,这意味着所有浏览器都会忽略它,除非特别配置为假装不支持框架。您的意思是说
iframe
元素具有
src
属性,指的是包含相同元素的文档吗?是的。我更新了这个例子,使它不那么做作。我的错误。事实证明,对于不支持iFrame的用户代理来说,这些按钮只是作为后备内容处理的。我将对其进行编辑,以从源代码中实际提取iFrame,这就是我实现的方式。
<!doctype html>
<html>

  <head>
    <title>Test Iframe</title>
  </head>

  <body>
    <button id="subscribe">Subscribe</button>
  </body>

 </html>