我在A页面有一个文本框和一个按钮,我想点击按钮以后,弹出一个窗口B页面,B页面是一个表格,点击表格的一行,把表格当前行的第一个单元格的值传到A页面的文本框内。可以实现A页面无刷新吗?请帮忙,谢谢

解决方案 »

  1.   

    http://topic.csdn.net/u/20090226/17/19ff150a-e000-407d-a24b-d0ea88804999.html你的问题和这个基本相同自己看吧
      

  2.   

    可以用opener获取父窗口,来调用父窗口的函数
    A.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>A</title>
    <script type="text/javascript">
    function setTextValue(val){
    document.getElementById("test").value = val;
    }
    </script>
    </head><body>
    <input type="text" id="test" />
    <input type="button" value="取值" onclick="window.open('B.html','b','');" />
    </body>
    </html>
    B.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>B</title>
    <script type="text/javascript">
    function setValue(obj){
    var val = obj.innerHTML;
    window.opener.setTextValue(val);
    }
    </script>
    </head><body>
    <table >
    <tr><td onclick="setValue(this);">第一列</td><td onclick="setValue(this);">第二列</td></tr>
    </table>
    </body>
    </html>
      

  3.   

    可以用opener获取父窗口,来调用父窗口的函数
    A.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>A</title>
    <script type="text/javascript">
    function setTextValue(val){
    document.getElementById("test").value = val;
    }
    </script>
    </head><body>
    <input type="text" id="test" />
    <input type="button" value="取值" onclick="window.open('B.html','b','');" />
    </body>
    </html>
    B.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>B</title>
    <script type="text/javascript">
    function setValue(obj){
    var val = obj.innerHTML;
    window.opener.setTextValue(val);
    }
    </script>
    </head><body>
    <table >
    <tr><td onclick="setValue(this);">第一列</td><td onclick="setValue(this);">第二列</td></tr>
    </table>
    </body>
    </html>
      

  4.   

    L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>a.html</title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
    <h3>a.html</h3>
      <input type="text" id="txtInput" /><input type="button" id="btnOpen" value="Open B" />
      <script type="text/javascript">
      <!--
    var oBtn = document.getElementById("btnOpen");
    oBtn.onclick = function() {
    window.showModelessDialog("b.html", window);
    };
      //-->
      </script>
     </body>
    </html><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>b.html</title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
      <h3>b.html</h3>
      <table id="tabTest" border="1">
    <tr>
    <td>1</td>
    <td>a</td>
    <td>b</td>
    </tr>
    <tr>
    <td>2</td>
    <td>c</td>
    <td>d</td>
    </tr>
    <tr>
    <td>3</td>
    <td>e</td>
    <td>f</td>
    </tr>
      </table>
      <script type="text/javascript">
      <!--var parentWin = window.dialogArguments;
    var oTxt = parentWin.document.getElementById("txtInput");var oTab = document.getElementById("tabTest");
    for (var i=0; i<oTab.rows.length; i++)
    {
    oTab.rows[i].onclick = function() {
    oTxt.value = this.cells[0].innerHTML;
    this.style.cursor = "hand";
    };
    }  //-->
      </script>
     </body>
    </html>
      

  5.   

    A 页面代码:<html>
    <body>
    <input type="input" id="show" name="show" /> <input type="button" id="btn" name="btn" value="点击" onclick="window.open('b.html')" />
    </body>
    </html>B 页面代码:
    <table border="1" onclick="getrow(this)">
    <tr>
    <td>a1</td>
    <td>a2</td>
    </tr>
    <tr>
    <td>b1</td>
    <td>b2</td>
    </tr>
    </table><script>
    // 为表格 tr 添加事件
    function getrow(obj)
    {
       if(event.srcElement.tagName=="TD"){
       curRow=event.srcElement.parentElement;

       window.opener.document.getElementById('show').value = curRow.cells[0].innerText;
       }
    }</script>
    其他需求,可以参照例子来修改。
      

  6.   

    如果你用open打开的窗口,就用document.opener得到父窗体对象!
    如果你用showModelsDialog打开的窗口,就用dialogArguments得到父窗体对象!