我試圖在我的頁面上打開fancybox iframe。將一些基本信息傳遞給iframe。然後,我想讓iframe與其父母交談。Fancybox(jQuery) - 將信息從父級傳遞給iframe和iframe回到父級
我傳遞填充NameID-1在整個靜態,但我真的想有這樣的可變如:var nameid=$(this).attr('nameid')
我只是不知道,因爲我是新來的Ajax如何將所有正確執行這個/ Javascript和與邏輯掙扎。
base.html文件
JS:
<script type='text/javascript'>
//<![CDATA[
// Popup Function
$(document).ready(function() {
$('a.openinformation').fancybox({
openEffect: 'fade',
openSpeed: 500 //,
});
});
// Update from iFrame
function setInformation(userText) {
$('#displayfield-nameid-1').html(userText);
$('#showhide-nameid-1').show();
}
//]]>
</script>
HTML:
<div>
<a class="openinformation fancybox.iframe" href="iframe.html" nameid= "1" originalname="Mary Poppins" >Mary Poppins</a>
</div>
<div id ="showhide-nameid-1" style=" display:none; background:#0CF;">
<p>Replacement Name: <span id="displayfield-nameid-1"></span></p>
</div>
Iframe.html的
JS:
<script type='text/javascript'>
//<![CDATA[
// Start
$(window).load(function() {
// When Loaded get going.
$(document).ready(function() {
$('a.doupdate').click(function() {
parent.setInformation($(this).text());
parent.$.fancybox.close();
});
$('a.closeremove').click(function() {
parent.$('#showhide-nameid-1').hide();
parent.$.fancybox.close();
});
});
});
//]]>
</script>
HTML
<p>The old name: $originalname;</p>
<p>The id for this column is: $nameid</p>
<p>Please select a new name:</p>
<div><a class="doupdate" href="#">Display new married name : Mary Smith</a></div>
<div><a class="doupdate" href="#">Display new married name: Sandy Shore</a></div>
<div><a class="closeremove" href="#" id="1">Clear (Hide) married Names Box</a></div>
感謝這麼好的書面和解釋的迴應。我非常感謝知道答案的推理。不僅僅是答案本身。超級大謝謝你! – Brandrally 2014-10-20 23:52:46