gpt4 book ai didi

javascript - 如何访问嵌套在 DOM 中的项目值?

转载 作者:行者123 更新时间:2023-11-30 09:09:34 25 4
gpt4 key购买 nike

我需要从嵌套 3 层和 4 层深的父表单访问表单和 iframe 中的值。

基本上,树层次结构 (DOM) 似乎如下所示:

<form name="formname" ....>
<iframe id="refframe">
<form name="formname" ...> ==> Level 3
<iframe id="iframe1"> ==> Level 4

现在我在第 3 层有一个项目值(比如 myValue),我想从顶层(父级 - 第 1 层)访问它

使用 JavaScript,我如何从父顶级访问这个项目“myValue”?

在 iframe1 的 iframe id 中访问级别 4 的项目也是如此

基于以上,我仍然不确定如何访问信息,但如果我有以下 HTML 代码:

<div class="tabs0">
<iframe id="refframe" width="1210px" height="584px" frameborder="0" align="left"

overflow="auto" src="http://www.example.com" home="" name="Site1">
</iframe>

</div>

<div class="tabs1">
<iframe id="refframe" width="1210px" height="584px" frameborder="0" align="left" overflow="auto" src="http://www.def.com" name="Site2">

如何从父窗口访问 tabs1 类 iframe 中的 src 值,即

src="http://www.def.com"

最佳答案

iframe 中的内容是否从与父文档相同的域加载?如果不是,则由于浏览器安全限制 ( same domain policy ),您将无法通过 javascript 访问它。

如果它来自同一个域,您应该能够毫无问题地使用 getElementById

关于javascript - 如何访问嵌套在 DOM 中的项目值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1452638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com