如何访问iFrame复选框元素 [英] How to Access iFrame Checkbox Elements
问题描述
有人可以告诉我,如果我有一个由复选框(父级)组成的网页,并且在同一个网页上,我也有一个来自另一个页面的iframe,该页面显示了许多记录,还有一个针对每条记录的复选框(子),如果我勾选父复选框,我想将此级联到iframe中的所有子复选框以及禁用这些子复选框。
Can someone please let me know that if I have a web page that consists of a checkbox (parent) and on this same web page, I also have a iframe that is sourced from another page that displays a number of records, which also has a checkbox (children) against each record, if I tick the parent checkbox, I would like to cascade this through to all children checkboxs within the iframe as well as disable these children checkboxes.
非常感谢一些帮助,因为我不知道如何访问iframe中的复选框。
Would really appreciate some help with this as I am not sure how to access the checkboxes within the iframe.
手册页上我的iframe定义类似如下:
My iframe definition on the man page is similar to the following:
<iframe id="iframe1" src="'+URL+'" style="border:none;width:799px;height:200px;" frameborder="1" framespacing="0" marginheight="0" marginwidth="0"></iframe>
任何示例/网站都会很棒。
Any examples/websites would be great.
感谢。
Tony。
Thanks. Tony.
推荐答案
好的,这是一个例子...
Okay here is an example...
首先这里是iFrame内容的来源(我称之为FramePage.htm)......
First here is the source for the iFrame contents (I called it FramePage.htm)...
<body>
<input id="Checkbox1" type="checkbox" name="checkbox" />
<input id="Checkbox2" type="checkbox" name="checkbox"/>
<input id="Checkbox3" type="checkbox" name="checkbox" />
</body>
以下是包含iFrame的页面上的来源...
Here is the source on the page that houses the iFrame...
<iframe id="frame" src="FramePage.htm"></iframe>
<input id="Button1" type="button" value="button" onclick="setData()" />
<script type="text/javascript">
function setData()
{
var frame = document.getElementById('frame');
var checkboxes = frame.contentWindow.document.getElementsByName('checkbox');
for (var i = 0; i < checkboxes.length; i++)
{
checkboxes[i].checked = true;
}
}
</script>
单击父页面上的按钮将选中框架上名称为checkboxes的所有复选框页。
Clicking the button on the parent page will select all the checkboxes with the name 'checkboxes' on the frame page.
希望这有助于:)
这篇关于如何访问iFrame复选框元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!