您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > JSP >

使用js在父子窗口间进行传值

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 10:00 点击:

我使用js在父子之间进行传值主要是通过在子窗口调用父窗口的方法来实现传值的目的。
 
parent.html
Html代码 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    <title>parent.html</title> 
     
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="this is my page"> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
     
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> 
    <script type="text/javascript"> 
        function openWin() { 
            var style = "width=300,height=400,location=no,directories=no,toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no"; 
            window.open("child.html","打开窗口传值",style);        
        } 
         
        function setValue(name,hname) { 
            document.getElementById("name").value = name; 
            document.getElementById("hname").value = hname; 
        } 
    </script> 
  </head> 
   
  <body> 
    name:<input type="text" id="name"/><a href="#" onclick="openWin()">请选择</a> 
    <input type="hidden" name="name" id="hname"/> 
  </body> 
</html> 
 
child.html
Html代码 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    <title>child.html</title> 
     
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="this is my page"> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
     
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> 
    <script type="text/javascript"> 
        function selectedThis(obj) { 
            var name = obj.value; 
            var hname = obj.id; 
            window.opener.setValue(name,hname);//调用父窗口的方法进行传值 
            window.opener = null; 
            window.close(); 

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • JSP与Servlet
    • 自己动手写MiniBBS系列(基本篇)之用户登录
    • JSP取当前日期
    • JDBC 入门(一)
    • 打开一个jsp页面默认查询所有数据,调用action
    • 使用JSP标签库验证用户的输入(2)完
    • WIN98/2000下的jsp服务器
    • 自定义JSP标签(tag)浅议
    • Struts学习傻瓜式入门篇
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1