这是子窗口print.aspx  的js
<script type='text/javascript'>
       var jydbh=window.dialogArguments.document.getElementById('txtjydbh');  
       var ysfs = window.dialogArguments.document.getElementById('ddlysfs');
       document.getElementById('lbljydbh')=jydbh.value;  
        //将从父窗口获取到的值赋予lbljydbh控件  怎么就不行呢?     

</script>

解决方案 »

  1.   

    还是解决不了 大家对showModalDialog传过来的值 是怎么处理的呢?
    给个建议啊
      

  2.   

    document.getElementById('lbljydbh').value=jydbh.value;  试试呢?
      

  3.   


    不行啊  这么做的话 提示  
    Microsoft JScript 运行时错误: 'document.getElementById(...)' 为空或不是对象
      

  4.   

    父窗口代码    function openpri()
        {
            var jydbh = document.getElementById("txtjydbh").value;
            //var zdtime = document.getElementById("txtjhrq").value;
            var ysfs = document.getElementById("ddlysfs").value;
            revalue = window.showModalDialog('print.aspx',window,'dialogHeight:530px;dialogWidth:698px;dialogTop:screen.height/2;dialogLeft:screen.width/2; edge:sunken ; center: Yes; help: No; resizable: No; status: No; scroll:yes;');
        } <asp:Button ID="btnPrint" runat="server" Text="打印预览" AccessKey="p"  OnClientClick="openpri();"  />子窗口print.aspx 代码
    <script type='text/javascript'>
           var jydbh=window.dialogArguments.document.getElementById('txtjydbh');  
           var ysfs = window.dialogArguments.document.getElementById('ddlysfs');
           alert(jydbh.value);
           alert(ysfs.value);//这边都有值
           document.getElementById('lbljydbh').value=jydbh.value;//到这步就是获取不到值
    </script>
     <div  style="position:absolute; left: 382px; top: 62px; width: 147px;"><asp:Label ID="lbljydbh" runat="server" ></asp:Label></div>
      

  5.   

    --------------------showModalDialog传递 参数方法 -----------
    ---a.js--A.html调用的js
    var arrParam = [];// 首次创建个数组
      arrParam[0]   ="张三";//姓名    
      arrParam[1]   ="18";//年龄   
      var   retuPar=window.showModalDialog(B.html',arrParam); //打开窗口并且传值--arrParam--B.html会接到数组
    ---b.js--B.html调用
    var   arrParam   =   window.dialogArguments;//  dialogArguments就是 父页面传递过来的参数集合 ---B.html 调用 
    document.getElementById("nametxt").value = arrParam[0]; 
    document.getElementById("agetxt").value = arrParam[1]; 
    这样就将结果传递过来并且使用了 然后你还可以关闭 这个子页面将结果反回去 可以是任意类型 也可以是数组 
    例如:
     var arrdata=new Array();
        arrdata[0]="ok";
    window.returnValue=arrdata;
    window.close(); //关闭打开的窗口
    这样就将arrdata这个数组返回给 父亲窗体的 retuPar 了 。
      

  6.   

    看不明白的话我给你做了个例子 你按照代码复制保存成4个文件就可以了。
    第一个文件 A.html<html xmlns="http://www.w3.org/1999/xhtml">
    <META http-equiv=Content-Type content=text/html;charset=gb2312>
    <head>
     
        <script src="a.js"></script>
    </head>
    <body>
     <form>
    姓名:<input type='txt' value='' id='name'><br>
    年龄:<input type='txt' value='' id='age'><br>
    <input type = 'button' onclick='showmod()' value='传递到子窗体'>
     </form>
    </body>
    </html>第二个文件<html xmlns="http://www.w3.org/1999/xhtml">
    <META http-equiv=Content-Type content=text/html;charset=gb2312>
    <head>
     
        <script src="b.js"></script>
    </head>
    <body>
     <form>
    接收到姓名:<input type='txt' value='' id='name'><br>
    接收到年龄:<input type='txt' value='' id='age'><br>
    输入返回值:<input type='txt' value='' id='jg'><br>
    <input type = 'button' onclick='retClose()' value='关闭返回'>
     </form>
    </body>
    </html>第三个文件function showmod()
    {
        var arrayList  = [];
        arrayList[0] = document.getElementById("name").value;
        arrayList[1] = document.getElementById("age").value;
        var revalue = window.showModalDialog('B.html',arrayList,'dialogHeight:530px;dialogWidth:698px;dialogTop:screen.height/2;dialogLeft:screen.width/2; edge:sunken ; center: Yes; help: No; resizable: No; status: No; scroll:yes;'); 
        alert("返回结果为:"+revalue[0]);
    }第四个文件window.onload = loadPar; //初始化加载
    //接收主窗体传递过来的参数
    function loadPar() 
    {
    var  arrParam  =  window.dialogArguments;
    document.getElementById("name").value = arrParam[0]; 
    document.getElementById("age").value = arrParam[1];
    }
    //返回
    function retClose()
    {
       var arrdata=new Array(); 
         arrdata[0]=document.getElementById("jg").value;
    window.returnValue=arrdata; 
    window.close(); 
    }
      

  7.   

    第一个文件叫 
    a.html
    第二个文件叫
    b.html
    第三个文件叫
    a.js
    第四个文件叫
    b.js 
    不让我编辑。。
      

  8.   

    jiangsong2004 你好这个我知道的 问题是 我的页面是aspx  好像有区别啊
      

  9.   

    没任何区别 aspx 和 html htm jsp 都是 加载后都是静态夜 这个我在PHP jsp aspx asp 都用过你不用怀疑 绝对好用的
      

  10.   

    我将A.html改为了 jiedan.aspx 代码如下
    var arrayList = [];
            arrayList[0] = document.getElementById("txtjydbh").value;
            arrayList[1] = document.getElementById("ddlysfs").value;
            var revalue = window.showModalDialog('print.aspx',arrayList,'dialogHeight:530px;dialogWidth:698px;dialogTop:screen.height/2;dialogLeft:screen.width/2; edge:sunken ; center: Yes; help: No; resizable: No; status: No; scroll:yes;');
        }b.html改为了print.aspx 代码如下
           function getValue()
           {
                var arrParam = window.dialogArguments;
                document.getElementById("lbljydbh").value = arrParam[0];
                document.getElementById("lblysfs").value = arrParam[1];
           }window.onload = loadPar; //初始化加载 ,这个要写在哪里呢?
    page_load()中?  怎么写????
      

  11.   



    帮我改成aspx页面的吧  
      

  12.   

    如果用document.getElementById("lbljydbh")= arrParam[0]; 提示以下错误:
    Microsoft JScript 运行时错误: 错误的参数个数或无效的参数属性值如果用document.getElementById("lbljydbh").value= arrParam[0]; 提示以下错误:
    'document.getElementById("lbljydbh")' 为空或者不是对象
      

  13.   

    document.getElementById("lbljydbh")  是你 子窗口的控件?  是.net 的自带服务器端控件还是?
      

  14.   

    window.onload 是在javascript下调用的 
      

  15.   

    html 跟aspx页面有很大的却别啊帮我改成aspx页面的吧   
    jiangsong2004
      

  16.   

    如果你只传不返回的话你可以 通过 URL 来传递参数 
      

  17.   


    是的 我只要把父窗口的值(父窗口有许多的label 需要传值) 传到子窗口 不用返回值 
    用的是vs2008
      

  18.   

    我做的是打印预览的效果 父窗口 中有一个保存按钮 一个打印预览按钮  
    保存完后,就通过jydbh这个参数 马上获取这票的信息
    我原来也是用的url传值的 但是  刚保存进去的  不能马上取出值(好像有缓存吧)var revalue = window.showModalDialog('print.aspx?jydbh='"+jydbh+"'','','dialogHeight:530px;dialogWidth:698px;dialogTop:screen.height/2;dialogLeft:screen.width/2; edge:sunken ; center: Yes; help: No; resizable: No; status: No; scroll:yes;');jydbh  已经可以传到子窗口  然后再根据这个参数 来获取所有的信息  string strsql = "select jydbh,jhrq,ysfs,sxhh,sdz,zdz,thfs from jydxx where jydbh='"+jydbh+"'  ";
               SqlCommand cmd = new SqlCommand(strsql, conn);
              SqlDataReader rdr = cmd.ExecuteReader();
      

  19.   

    jiangsong2004
    jiangsong2004
    jiangsong2004