我点击修改数据的时候,需要弹出一个窗口,需要修改的数据放在窗口中,现在后台的数据是取道了,窗口也弹出了,但是没有数据,我估计是url出错了,我只用了struts的execute一个方法实现的CRUD,
后面是用if判断执行操作的
js代码
 function doUpdate(operate){
      var url = "<%=path%>/test.do?operate=updateInit";
      var returnValue = window.showModalDialog(url,"testPage","dialogWidth:500px;status:no;dialogHeight:400px");
      
      //document.forms[0].operate.value = "updateInit";         //我也知道没提交到后台,所以没显示,但是要想提交,应该怎么写?
      //document.forms[0].operAtt.value = operate;
      document.forms[0].submit();
   }
触发事件的代码
<a href="#" onclick="doUpdate('<bean:write name="vo" property="yydm"/>')">修 改</a></td>

解决方案 »

  1.   

    window.showModalDialog的第二个参数就是传递到打开的窗口的参数
    在打开的窗口用window.dialogArguments获取该参数
    给你个例子caller.html <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Caller</title>
    <script type="text/javascript">
    function openPage(elem, page){
    var loading = document.createElement('span');
    loading.innerHTML = 'loading';
    var arg = {
    window: window,
    input: document.getElementById('input'),
    loading: function(){
    elem.parentNode.replaceChild(loading, elem);
    },
    finished: function(){
    loading.parentNode.replaceChild(elem, loading);
    }
    };
    var val = window.showModalDialog(page, arg, 'status:no;dialogWidth:300px;dialogHeight:300px');
    !val || alert(val);
    }
    </script>
    </head>
    <body>
    <a hre="#" onclick="openPage(this, 'input.html');" style="cursor:hand">open</a>
    <textarea id="input"></textarea>
    </body>
    </html>input.html <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Input</title>
    <script type="text/javascript">
    var arg = window.dialogArguments;
    if (arg.loading) arg.loading();
    window.onload =function(){
    window.returnValue = 'test';
    if (arg.finished) arg.finished();
    var done = document.getElementById('done'),
    input = document.getElementById('input');
    done.onclick = function(){
    arg.input.value = input.value;
    }
    }
    </script>
    </head>
    <body>
    <textarea id="input"></textarea>
    <input type="button" id="done" value="done" />
    </body>
    </html>
      

  2.   

    LZ这段代码写了双重请求,一个是window.showModalDialog请求,一个是form的submitLZ首先要理清思路,我估计是弹出窗口显示数据库中某记录信息,然后可以在弹出窗口中修改
    这个时候应该用window.showModalDialog弹出窗口,URL请求后台取出数据
    然后在弹出窗口用form提交修改数据,修改完数据后关闭弹出窗口,刷新父页面
      

  3.   

    首先感谢楼上几位
    但是怎么写?我写到这一步实在是写不下去了,因为我的意思是,要让url里面的请求进入action里面,把数据查询出来,然后放在窗口中,如果用的是DispatchAction很好实现的,但是我现在只用了一个Execute方法,继承的是Action。懂我意思吧,
    action里面是if(flag.equals("query")){   这个里面是查询代码
      }
    if(flag.equals("del")){
       删除代码
    }


      

  4.   

    LZ,注意window.showModalDialog会中断当前页面JS的执行,只有当打开的窗口关闭后才会继续
      

  5.   

    这个是模块代码
     function doUpdate(operate){
          
          var url = "yymkb.do?operate=updateInit";
          var returnValue = window.showModalDialog(url,"test","dialogWidth:500px;status:no;dialogHeight:300px");
          
          //document.forms[0].operate.value = "updateInit";
          //document.forms[0].operAtt.value = operate;         //这几步我也知道走不到的
          document.forms[0].submit();
       }action代码                              //调试的时候 action代码都没进来
     if(dealMethod.equalsIgnoreCase("updateInit")){
         String operId = yymkbForm.getOperAtt();
         //System.out.println(operId);
         YymkbBLH yymkbBLH = new YymkbBLH();
         list = yymkbBLH.getPrimaryKeyData(conn, operId);
         if(list.size() > 0){
            YymkbVO vo = (YymkbVO)list.get(0);
             try {
    BeanUtils.copyProperties(yymkbForm,vo);
    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
            forward = "updateInit";
         }
        }