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
相关文档:
函数一、写cookie的函数,将Cookie写入客户端,通用函数,传入3个参数即可(Cookie名字,值和失效期)
//函数:写入cookie
function WriteCookie (cookieName, cookieValue, expiry)
{
var expDate = new Date();
if(expiry) //如果设置了cookie失效时间;
{
expDate.setTime (expDate.getTime() expiry);
documen ......
public static void Main()
{
WebRequest req = WebRequest.Create("http://blog.csdn.net/xiaofengsheng");
try
& ......
replace方法的语法
是:stringObj.replace(rgExp, replaceText)
其中stringObj是字符串(string),reExp可以是正则表达式对象(RegExp)也可以是字符串
(string),replaceText是替代查找到的字符串。。为了帮助大家更好的理解,下面举个简单例子说明一下
<script language="javascript">
var str ......
html:
<div id="slide-box">
<div id="slide">
<div id="fbshutter" style="width:1px;">
<img id="bPic" src="images/01.gif" /> </div>
  ......
关于This
1. 它是一个关键字,并不是变量名或属性名。
2. 它实际指function所关联的对象,如果function没有关联任何对象,则this是Global对象
var msg = 'I am global';
function showMsg(){
alert(this.msg);
};
function nestedShowMsg (){
var nested = function(){
alert(this.msg);
};
nested();
......