易截截图软件、单文件、免安装、纯绿色、仅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检测 .net Framework

通过请求的header中可以看到  User-Agent 项
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; Tablet PC 2.0; CIBA)
这里记录了本地信息,通过这里的.Net CLR xxxxx,可以判断 ......

利用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验证代码(用户名,密码,邮箱)

<script language="javascript">
function IsDigit(cCheck)
{
return (('0'<=cCheck) && (cCheck<='9'));
}
function IsAlpha(cCheck)
{
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
}
function IsaNull(cCheck) ......

javascript中Date和string的互转

js是弱类型的 但是某些时候 你还真需要一个date
比如说 指定时间 那么3个小时后是什么时间
这样的函数 自己写就麻烦了
转成Date
var hs = Date.parse('03/02/2009 22:10');
 var d = new Date(hs);
 document.write(d);
 
 document.write('<br/>');
 var h=3.5;
 var arrh= ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号