获取iframe内的标签

get to the label inside an iframe

本文关键字:标签 iframe 获取      更新时间:2023-09-26

有人能告诉我如何通过JavaScript在iframe内获得label1吗?

WebForm1.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="calendar">
        <iframe src="WebForm2.aspx"></iframe>
    </div>
    </form>
</body>
</html>

WebForm2.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr><td class="default"><label id="label1">Label1</label></td></tr>
        </table>
    </div>
    </form>
</body>
</html>

给iframe一个Id,例如

<iframe src="WebForm2.aspx" id="webForm" ></iframe>

然后,为了获得对字段"lable1"的访问权限,您必须给出以下代码

(document.getElementById("webForm")).contentWindow.document.getElementById("label1").innerHTML;

希望这对你有帮助