在iframe子页面获取父页面元素 代码如下: 代码如下: $('#objld', parentdocument); 在父页面获取iframe子页面的元素 代码如下: 代码如下: $("#objid", documentiframes('iframe')document) 或 代码如下: $(documentgetElementById('ifram
方法只有一种:
步骤:
1、获取iframe节点
2、获取iframe中的变量
示例
ahtml
<iframe id='x' name='x' src='bhtml'/>
bhtml
<script>
var y='1';
</script>
在ahtml中获取y,则可以通过以下方式
documentframes['x']y //先获取frame,在获取y
间接实现, 先获取iframe页面值到本页面 然后在提交
indexjsp中包含2个frameset
<frameset rows="98," frameborder="no" border="0" framespacing="0">
<frame src="ajsp" name="aFrame" id="aFrame" />
<frame src="bjsp" name="bFrame" id="bFrame" />
</frameset>
<input type="hidden" name="保存a页面的值" value="" />
<script>
var aValue = windowdocumentgetElementById("aFrame")contentWindowdocumentgetElementById("a页面中的元素");
documentgetElementById("保存a页面的值")value = aValue;
然后在提交indexjsp到action
</script>
最近在开发时遇到使用了Iframe的情况,在一个父窗口里使用了Iframe,之后又想在父窗口中使用JQuery来获得Iframe里的元素,之前有使用过,久没使用就忘了,今日记录下来。
格式:
事例:
格式:
事例:
格式:
事例:
格式:
事例:
用session()
在bjsp里写
session("aa")=eeee 或者session("aa")=requestform("tt")
然后在ajsp里就能读到session("aa")的值了 responsewrite(session("aa"))。当然,要从b页面链接跳到a页面,那样a页面才能读到b页面的值,要不然a页面也b页面没有关系,session是没用用的。
还不明白的话可以补充问
同域或跨子域读写 *** 作 iframe 里的内容
父页面读写 *** 作子页面:
HTML code<iframe id="test-iframe" name="test-iframe" src="childhtml" scrolling="no" frameborder="0"></iframe>
<script>
windowonload = function () {
/
下面两种获取节点内容的方式都可以。
由于 IE6, IE7 不支持 contentDocument 属性,所以此处用了通用的
windowframes["iframe Name"] or windowframes[index]
/
var d = windowframes["test-iframe"]document;
dgetElementsByTagName('h1')[0]innerHTML = 'pp';
alert(dgetElementsByTagName('h1')[0]firstChilddata);
}
</script>
获取父级页面,你只需获取到父级的window就可以做获取数据 *** 作,windowparent即为iframe获取父级页面window的方法。
想要获取iframe被替换的ajsp的数据,如果数据比较大,你就保存在父级window里面;数据较小比如是一个字符串之类的,那就在你ajsp *** 作locationhref改变为bjsp时将数据带上url后面作为传参,例如locationhref = "bjspxxx=xxx"。
在iframe子页面获取父页面元素
代码如下:
$('#objld', parentdocument);
在父页面获取iframe子页面的元素
代码如下:
$("#objid", documentiframes('iframe')document)
或
代码如下:
$(documentgetElementById('iframeId')contentWindowdocumentbody)html() $(documentgetElementById('iframeId')contentWindowdocumentbody)html()
显示iframe中body元素的内容
代码如下:
$("#testId", documentframes("iframename")document)html()
(1)父页面获取iframe中的元素值:
Js代码
1//根据iframe的id获取对象2var i1 = windowframes['iframeId'];
3//var iframe =windowframes[0];也可以
4//获取iframe中的元素值
5var val=i1documentgetElementById("t1")value
//根据iframe的id获取对象
var i1 = windowframes['iframeId'];
//var iframe =windowframes[0];也可以
//获取iframe中的元素值
var val=i1documentgetElementById("t1")value
(2)在iframe中获取父页面中的元素值:
Js代码
1var val = parentdocumentgetElementById("txt1");var val = parentdocumentgetElementById("txt1");
(3)a包含2个iframe分别为b,c,现在从b中获取c中的元素的值:
Js代码
1var i1 = parentwindowframes['iframeId'];2var val = i1documentgetElementById("text1")value;
var i1 = parentwindowframes['iframeId'];
var val = i1documentgetElementById("text1")value;
以上就是关于javaweb 在页面中使用iframe嵌套一个子页面,那子页面怎么获取Servlet转发到父页面时request中的参数呢全部的内容,包括:javaweb 在页面中使用iframe嵌套一个子页面,那子页面怎么获取Servlet转发到父页面时request中的参数呢、请问JS中怎么取到iframe标签里的值、struts1 action 中如何获得不同iframe中的数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)