我已经冲刷的interwebs,发现从一个元素的值相当多,涉及到什么我想要做的答案,如:
Javascript - Get element from within an iFrame
How can I access iframe elements with Javascript?
Access iframe elements in JavaScript使用jQuery获得一个iFrame
没有正确的结果。
我目前在iFrame中有一个测试框。从父母,我需要获得文本框onBlur()
的价值。
我目前正在使用;
alert("before");
var iframe = document.getElementById('GeneralInformationPrivate.aspx');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
//innerDoc.getElementById("imageLoc").hide();
alert("after");
随着线条评论,我看到两个警报。没有它评论,它没有得到那么多。
(我隐藏它只是一个测试 - 哪个不起作用)。
任何人都可以指向正确的方向。
编辑 加载的iFrame的HTML看起来像这样:
<iframe id="GeneralInformationPrivate.aspx" class="iframetab" src="GeneralInformationPrivate.aspx"><!-- Controls Here --></iframe>
编辑2个 I帧被加载像这样。 (在父)
<div style="float: right; width: 570px;">
<div id="tabs">
<ul style="">
<li><a class="tabref" href="#tabs-1" rel="GeneralInformationPrivate.aspx">General</a></li>
<li><a class="tabref" href="#tabs-2" rel="www.google.co.za">Friends</a></li>
<li><a class="tabref" href="#tabs-3" rel="">Challenges</a></li>
</ul>
<div id="tabs-1">
</div>
<div id="tabs-2">
</div>
<div id="tabs-3">
</div>
</div>
</div>
在文件加载(仍在父)
// ++ IFRAME TABS
var $tabs = $('#tabs').tabs(); //Set the tab
//Loads the initial tab
function getSelectedTabIndex() {
return $tabs.tabs('option', 'selected');
}
beginTab = $("#tabs ul li:eq(" + getSelectedTabIndex() + ")").find("a");
//Send the correct data to load
loadTabFrame($(beginTab).attr("href"), $(beginTab).attr("rel"));
// Does something everytime you click the tab
$("a.tabref").click(function() {
//event code
});
//Load the actual iFrame
function loadTabFrame(tab, url) {
if ($(tab).find("iframe").length == 0) {
var html = [];
html.push('<div class="tabIframeWrapper">');
html.push('<iframe id="'+ url +'" class="iframetab" src="' + url + '">Load Failed?</iframe>');
html.push('</div>');
$(tab).append(html.join(""));
//$(tab).find("iframe").height($(window).height() - 80); // Set the height of the iFrame (Currently using CSS - See controlStyle.css iFrame)
}
return false;
}
//Make sure its only loaded on click
$("a.tabref").click(function() {
loadTabFrame($(this).attr("href"), $(this).attr("rel"));
});
// -- IFRAME TABS
其中THEL将页面加载到iFrame。
编辑3内容的iFrame的(对不起)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GeneralInformationPrivate.cs" Inherits="member.Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>General Information</title>
</head>
<body style="background: white">
<form id="form1" runat="server">
<div style="min-height: 100px; width: 100%; padding: 0px" id="divProInfo">
<table style="width: 100%">
<tr>
<td>
<div class="divRegInput" style="padding: 5px 0px 10px 15px">
<asp:Label ID="Label12" runat="server" Text="Image URL" Font-Bold="True"></asp:Label>
<asp:Label ID="Label13" runat="server" Text="make yourself look good" CssClass="styleLabelWatermarkWashout"></asp:Label>
<br />
<input id="imageLoc" class="styleTextBoxCenter Larger" />
</div>
</td>
</tr>
<tr>
<td>
<div class="divRegInput" style="padding: 5px 0px 10px 15px">
<asp:Label ID="Label6" runat="server" Text="Website URL" Font-Bold="True"></asp:Label>
<asp:Label ID="Label7" runat="server" Text="show others where you came from" CssClass="styleLabelWatermarkWashout"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" CssClass="styleTextBoxCenter Larger" />
<asp:Label ID="lblWebsiteTitle" runat="server" CssClass="styleLabelWatermark"></asp:Label>
</div>
</td>
</tr>
<%--<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" CssClass="styleButtonGreenHolder" Height="43px" CausesValidation="False" OnClick="btnChangeChallenge_Click" Width="195px" />
</td>
</tr>--%>
</table>
</div>
</div>
</form>
</body>
</html>
它必须完成嘿... – TheGeekZn 2013-03-13 10:30:43
你可以请你的HTML代码或例如jsfiddle吗? – 2013-03-13 10:30:48
我已经添加了代码。 - 使用iFrame。我没有删除任何东西,因为其他控件乱七八糟。 – TheGeekZn 2013-03-13 10:49:07