天天看點

子窗體與父窗體傳值操作的js示例

//傳回值給父窗體

function returnParent(value) {//擷取子窗體傳回值

   var parent = window.dialogArguments; //擷取父頁面

   //parent.location.reload(); //重新整理父頁面

   if (parent != null && parent != "undefined") {

       window.returnValue = value; //傳回值

       window.close(); //關閉子頁面

   }

//window.opener.document.getElementById("ActivityPic");//直接操作父窗體元素

   return;

}

//打開模式子窗體,擷取傳回值進行操作

function showModalOnly(me, url) { //彈出窗體 ,單選

   var hidden = document.getElementById(me); //擷取隐藏的控件

   if (hidden != null && hidden.value != null && hidden.value.length > 0) {

       alert("此處為單選,請先删除已有的選項,再次嘗試選擇。");

       return;

   var reValue = window.showModalDialog(url, window, "dialogHeight:500px; dialogWidth:987px;  status:off; scroll:auto");

   if (reValue == null || reValue == "undefined" || reValue == "") {

       return; //如果傳回值為空,就傳回

   var index = reValue.split("^"); //分割符 ^ 的位置

   if (index[0] == null || index[0] == "undefined" || index[0].length < 1) {

   var hid = index[0].split('&'); //為隐藏控件指派

   var view = index[1].split('&'); //顯示值

   var content = ""; //需要添加到check中的内容

   if (hid != null && hid.length == 2) {

       var i = 0;

       if (hid[i] != "undefined" && hid[i] != "" && view[i + 1] != "undefined" && view[i + 1] != "") {

           content += '<table  id="' + hid[i]

           + '" class="deleteStyle"><tr><td><img src="../../../Images/deleteimge.png" title="點選删除"  alt="删除" onclick=" deleteTable('

           + "'" + hid[i] + "'," + "'" + me + "'" + ');" /></td><td>' + view[i + 1] + '</td></tr></table>';

           hidden.value = hid[i]; //為隐藏控件指派

           var c = document.getElementById("check" + me);

           c.innerHTML += content;

           return;

       }

   alert("請隻選擇一條資料。");

function openUploadWindow(url, width, height,left,top) {

if(width==null) width=987;

if (height == null) height = 500;

if (left == null) left = 200;

if (top == null) top = 200;

//window.open(url, 'newwindow', 'height=' + height + ',width=' + width + ',top=200,left=200,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');

    window.showModalDialog(url, window, "dialogHeight:" + height + "px; dialogWidth:" + width + "px;status:off; scroll:auto;dialogLeft:"+left+"px;dialogTop:"+top+"px");

繼續閱讀