易截截图软件、单文件、免安装、纯绿色、仅160KB

Javascript怎么在两个窗体之间传值

原文:刘武|Javascript怎么在两个窗体之间传值  
众所周知window.open() 函数可以用来打开一个新窗口,那么如何在子窗体中向父窗体传值呢,其实通过window.opener即可获取父窗体的引用。
如我们新建窗体FatherPage.htm:
XML-Code:
<script type="text/javascript">
function OpenChildWindow()
{
    window.open('ChildPage.htm');  
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />
然后在ChildPage.htm中即可通过window.opener来访问父窗体中的元素:
XML-Code:
<script type="text/javascript">
function SetValue()
{
    window.opener.document.getElementById('txtInput').value
        =document.getElementById('txtInput').value;
    window.close();
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="SetFather" onclick="SetValue()" />
其实在打开子窗体的同时,我们也可以对子窗体的元素进行赋值,因为window.open函数同样会返回一个子窗体的引用,因此FatherPage.htm可以修改为:
XML-Code:
<script type="text/javascript">
function OpenChildWindow()
{
    var child = window.open('ChildPage.htm'); 
    child.document.getElementById('txtInput').value
        =document.getElementById('txtInput').value;
}
</script>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />
通过判断子窗体的引用是否为空,我们还可以控制使其只能打开一个子窗体:
XML-Code:
<script type="text/javascript">
var child
function OpenChildWindow()
{
    if(!child)   
        child = window.open('ChildPage.htm'); 
     child.document.getElementById('txtInput').value
         


相关文档:

利用javascript验证输入框中的值是否为日期格式

1、判断是否为年月日时间格式
<script>
//去除字符串首尾空格
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//验证是否为日期
function validator(){ 
    if(isDate(document.all.demo1.value.trim())==false){
 &n ......

JavaScript的replace方法与正则表达式讲解

 
replace方法的语法
是:stringObj.replace(rgExp, replaceText)
其中stringObj是字符串(string),reExp可以是正则表达式对象(RegExp)也可以是字符串
(string),replaceText是替代查找到的字符串。。为了帮助大家更好的理解,下面举个简单例子说明一下
<script language="javascript">
var str ......

纯JavaScript的渐开式幻灯片

html:
<div id="slide-box">      
    <div id="slide">
      <div id="fbshutter" style="width:1px;">
        <img id="bPic" src="images/01.gif" />  </div>
  ......

javascript学习心得(2)

内部数组
在Java中为了方便内部对象的操作,可以使用窗体(Forms)、框架(Frames)、元素(element)、链接(links)和锚(Anchors)数组实现对象的访问。
 anchors[]:使用《A name=“anchorName“》标识来建立锚的链接。
 links[]: 使用<A href=”URL”>来定义一个越文本链接项。
 Forms[]: 在程序 ......

三种不同位置的JavaScript代码的写法

三种不同位置的JavaScript代码的写法
 客户端脚本JavaScript在写法上其实有很多种方法,它们的放置位置也非常之多。。 下面列举在三种不同的地方写JavaScript代码,实现的效果都是点击按钮button弹出alert警告框
第一种是最常见的,代码如下 html代码
<input type="button" value="按钮1" id=" ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号