簡體   English   中英

從jquery模態對話框帽子鏈接返回到另一頁的值

[英]return value from jquery modal dialog hat links to another page

我正在創建一個jQuery模式對話框並將其鏈接到另一個頁面中的表單,如下所示:

var $dialog = $("<div></div>")
.html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>')
.dialog({
   autoOpen: false,
   modal: true,
   height: 400,
   width: 300,
   title: "Multiple HAWBs",
   buttons: {
        "Save": function() {
            $( this ).dialog( "close" );
        },
        "Cancel": function() {
            $( this ).dialog( "close" );
        }
    },
    close: function() {}
});
$dialog.dialog('open');
});

在鏈接頁面上,我有一個元素,並且我試圖從對話框中讀取所選值到我的父頁面,我該怎么做?

如果iframe的來源是其他域,則不能這樣做。 在其他情況下,您可以通過向該元素添加ID來訪問其內容

<iframe id="myiframe" style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>'

然后簡單地

document.getElementById('myiframe').contentWindow.document

看看這是否是您需要的東西: 這里

demo.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
<script>
$(document).ready(function(){
$(".click").on('click',function(){
    myDialog();
});
});
function myDialog(){
var $dialog = $("<div></div>")
.html('<iframe style="border: 0px;" id="frame" src="view1.php" width="100%" height="100%"></iframe>')
.dialog({
    autoOpen: false,
    modal: true,
    height: 400,
    width: 300,
    title: "Multiple HAWBs",
    buttons: {
         "Save": function() {
             var data="";
            var childrens= $($(document.getElementById('frame').contentWindow.document)[0].activeElement).children();//get allthe fields of dialog
         childrens.each(function(index){
     if(childrens[index].id == 'addme1'){
        data=data+childrens[index].value;//this is just to show you the reading of content of dialog.
        }

         })
             $( this ).empty();
            $("#parent").html(data);

             $( this ).dialog( "close" );
         },
         "Cancel": function() {
             $( this ).dialog( "close" );
         }
     },
     close: function() {

     }
});
$dialog.dialog('open');

}
</script>

<div>
<div id="parent">i'll be changed using dialog data</div>
<button class="click">Open Dialog</button>

view1.php

<input type="text" id="addme">
<input type="text" id="addme1">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM