javascript下我用
window.opener.document.getElementsByName("file").value=type;
向其父窗体传值,怎么出现错误啊?就是在a.jsp里通过提交表单到b.jsp。
b.jsp处理好以后再将处理的结果(type)传回给a.jsp路过的大侠帮帮啦!
小弟在此感激不尽!
有其他方法也行啊。

解决方案 »

  1.   

    window.opener.document.getElementsByName("file")返回的是一个array
    window.opener.document.getElementsByName("file")[0].value=type才能赋值
      

  2.   

    哦,我写错了!我用的是
    window.opener.document.getElementsByName("file")[0].value=type
    可还是出错啊!
      

  3.   

    还有我用alert(window.opener.document.getElementsByName("file")[0].value);
    都会出错。
      

  4.   

    我又alert(window.opener);
    出来的是undefiend
      

  5.   

    提交前alert(window.opener); 呢?
      

  6.   

    就是JavaScript没有什么提示啊!就是代码运行到
    alert(window.opener.document.getElementsByName("file")[0].value); 
    就不运行了。状态栏会显示网页有错误
      

  7.   

    没有提示。就是运行到window.opener.document.getElementsByName("file")[0].value=type 
    代码就不运行了,
    状态栏显示网页有错误
      

  8.   

    也是undefiend
    是不是浏览器有问题?
      

  9.   

    因为window.opener丢掉了.所以报错了.
    但是为什么丢掉了呢?你做提交处理前能拿到该对象吗?
      

  10.   

    不可能啊!我又没做什么与window.opener有关的代码。
      

  11.   

    额...对哦...你是表单提交的哦...应该不会动那个...那就奇怪了..
    把你A的FORM拿出来看看...
      

  12.   

    <script language="javascript">
    function uphead(){
    var url=document.getElementsByName("file")[0].value;
    var  n=url.lastIndexOf("\\")+1;
    var t=url.lastIndexOf(".")+1;
    var type=url.substring(t).toLowerCase();
    if(type=="jpg"||type=="gif"||type=="bmp"){
    var a=url.substring(n);
    n=a.lastIndexOf(".");
    a=a.substring(0,n);
    a=escape(a);
    a=a.replace(/%/g, "$")
    userInformation.action="upImage.jsp?name="+a+"&type="+type;
    document.getElementsByName("userInformation")[0].submit();
    }else{
    alert("仅限jpg、gif、bmp格式的图片文件!");
    }
    }
    </script>
    <form action="music.jsp" method="post" enctype="multipart/form-data" name="userInformation">
    <input type="file" onchange="uphead()" accept="image/jpeg" name="file" />
    </form>
      

  13.   

    改成<form action="music.jsp" method="post" enctype="multipart/form-data" name="userInformation" target="b"> 
    试试
      

  14.   

    参考^_^:
    问题是不是在于"通过提交表单"
    --<form action="b.jsp">??
    --------------
    window.opener
    对应于
    <script language="javascript">
    <!--
    window.open("b.jsp","???","???")
    //-->
    </script></body>
      

  15.   

    你的意思是通过表单提交的页面转换不能用window.opener?
      

  16.   

    改成target="_blank"好像提交不了了!
      

  17.   

    我的理解是
    <form action="b.jsp">
    b.jsp是a.jsp<form>参数接受者,两者是“兄弟”(或“上下级”)关系,而不是父子关系
    对吗?
     
      

  18.   

    a.jsp 在用户端运行
    通常b.jsp是在服务器端运行,而不是在用户端运行
    -----
    如果希望b.jsp在用户端运行,可以考虑:
    (a.jsp)window.open("b.jsp"+参数,"???","???") 
    (其中参数的长度不超限)
    参考^_^
      

  19.   

    我要用到<input type="file" onchange="uphead()" accept="image/jpeg" name="file" /> 啊!
    其他的到好办了。
      

  20.   

    try:
    <script language="javascript"> 
    function uphead(){ 
    var url=document.getElementsByName("file")[0].value; 
    var  n=url.lastIndexOf("\\")+1; 
    var t=url.lastIndexOf(".")+1; 
    var type=url.substring(t).toLowerCase(); 
    if(type=="jpg"||type=="gif"||type=="bmp"){ 
    var a=url.substring(n); 
    n=a.lastIndexOf("."); 
    a=a.substring(0,n); 
    a=escape(a); 
    a=a.replace(/%/g, "$") 
    // userInformation.action="upImage.jsp?name="+a+"&type="+type; 
    // document.getElementsByName("userInformation")[0].submit();
    window.open(upImage.jsp?name="+a+"&type="+type,"","width=100,height=100,left=0,top=0") 
    }else{ 
    alert("仅限jpg、gif、bmp格式的图片文件!"); 


    </script> 
    ------
    不知道upImage.jsp支持吗
    (PS:其实AJAX没多难)
      

  21.   

    他是要提交的话.window.open就不能直接用了.你试试下面这段.只有新打开的窗口才有window.opener这个对象的.test.html
    <script> 
    function aa(){
    alert(window.opener);
    }
    </script> 
    <form action="test.html" target='b'>
    <input type='submit'/>
    <input type='button' onclick='aa()'/>
    </from>保存的名字要对...
      

  22.   

    表单里有<input type="file" onchange="uphead()" accept="image/jpeg" name="file" /> 
    不能直接weindow.open();