如何打开弹出窗口并使用父窗口中的数据填充它? [英] How to open popup and populate it with data from parent window?
本文介绍了如何打开弹出窗口并使用父窗口中的数据填充它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用JavaScript / jQuery在父页面中使用来自JS变量的数据填充弹出窗口?
How can I use JavaScript/jQuery to populate a popup-window with data from JS-variables in the parent page?
在我的示例中,我有一个数组文件名。我在父窗口中最多列出五个,如果有更多,我想提供一个链接,打开一个弹出窗口并列出数组中的每个帖子。
In my example I have an array of filenames. I list at most five in the parent window and if there's more I want to provide a link that opens a popup window and lists each post in the array.
所以,如果我打开一个包含< ul id =all_files>< / ul>
的弹出式窗口,如何添加< li>
-items到该列表?
So if I open a popup that contains a <ul id="all_files"></ul>
, how can I add <li>
-items to that list?
推荐答案
父窗口:
<span id="popup"> Click to Open Popup </span>
<script type="text/javascript">
var ar=new Array("Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6",
"Item 7", "Item 8", "Item 9", "Item 10");
function getArray(){
return ar;
}
$(document).ready(function(){
$("span#popup").click(function(){
var p=window.open("Popup.html");
});
});
</script>
弹出窗口:
<ul id="list"></ul>
<script type="text/javascript">
if(window.opener && !window.opener.closed){
var ar= window.opener.getArray();
var items="";
for(var i=0;i<ar.length;i++){
items +="<li>" + ar[i] + "</li>";
}
$("ul#list").html(items);
}
</script>
这篇关于如何打开弹出窗口并使用父窗口中的数据填充它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文