一:JavaScript静态页面值传递之URL篇

能过URL进行传值.把要传递的信息接在URL上.

例子:

参数传出页面Post.htm—>

 

<input type="text"name="username">

<input type="text" name="sex">

<input type="button"value="Post">

<script language="javascript" >

function Post()

{

  //单个值 Read.htm?username=baobao;

  //多全值 Read.htm?username=baobao&sex=male;

  url= "Read.htm?username="+escape(document.all.username.value);

  url+= "&sex=" + escape(document.all.sex.value);

  location.href=url;

}

</script>

 

参数接收页面Read.htm—>

 

<script language="javascript" >

/*

*--------------- Read.htm -----------------

* Request[key]

* 功能:实现ASP的取得URL字符串,Request("AAA")

* 参数:key,字符串.

* 实例:alert(Request["AAA"])

*--------------- Request.htm -----------------

*/

var url=location.search;

var Request = new Object();

if(url.indexOf("?")!=-1)

{

  varstr = url.substr(1) //去掉?号

  strs= str.split("&");

  for(vari=0;i<strs.length;i++)

  {

     Request[strs[i].split("=")[0]]=unescape(strs[ i].split("=")[1]);

  }

}

alert(Request["username"])

alert(Request["sex"])

</script><script language="JavaScript">

<!--

function Request(strName)

{

var strHref ="www.abc.com/index.htm?a=1&b=1&c=测试测试";

var intPos = strHref.indexOf("?");

var strRight = strHref.substr(intPos + 1);

var arrTmp = strRight.split("&");

for(var i = 0; i < arrTmp.length; i++)

{

var arrTemp = arrTmp[i ].split("=");

if(arrTemp[0].toUpperCase() == strName.toUpperCase())return arrTemp[1];

}

return "";

}

alert(Request("a"));

alert(Request("b"));

alert(Request("c"));

//-->

</script>

<script>

String.prototype.getQuery = function(name)

{

  varreg = new RegExp("(^|&)"+ name+"=([^&]*)(&|$)");

  varr = this.substr(this.indexOf("?")+1).match(reg);

  if(r!=null) return unescape(r[2]); return null;

}

var str ="www.abc.com/index.htm?a=1&b=1&c=测试测试";

alert(str.getQuery("a"));

alert(str.getQuery("b"));

alert(str.getQuery("c"));

</script>

 

优点:取值方便.可以跨域.
缺点:值长度有限制

二:JavaScript静态页面值传递之Cookie篇

Cookie是浏览器存储少量命名数据.

它与某个特定的网页或网站关联在一起.

Cookie用来给浏览器提供内存,

以便脚本和服务器程序可以在一个页面中使用另一个页面的输入数据.

参数传出页面Post.htm—>

 

<inputtype="text" name="txt1">

<inputtype="button" value="Post">

<scriptlanguage="javascript" >

functionsetCookie(name,value)

{

/*

*---------------setCookie(name,value) -----------------

*setCookie(name,value)

* 功能:设置得变量name的值

* 参数:name,字符串;value,字符串.

* 实例:setCookie('username','baobao')

*---------------setCookie(name,value) -----------------

*/

  var Days = 30; //此 cookie 将被保存 30 天

  var exp = new Date();

  exp.setTime(exp.getTime() +Days*24*60*60*1000);

  document.cookie = name +"="+ escape (value) + ";expires=" + exp.toGMTString();

  location.href = "Read.htm";//接收页面.

}

</script>

 

参数接收页面Read.htm—>

 

<scriptlanguage="javascript" >

functiongetCookie(name)

{

/*

*---------------getCookie(name) -----------------

*getCookie(name)

* 功能:取得变量name的值

* 参数:name,字符串.

* 实例:alert(getCookie("baobao"));

*---------------getCookie(name) -----------------

*/

  var arr =document.cookie.match(new RegExp("(^|)"+name+"=([^;]*)(;|$)"));

  if(arr !=null) returnunescape(arr[2]); return null;

}

alert(getCookie("baobao"));

</script>

 

优点:可以在同源内的任意网页内访问.生命期可以设置.
缺点:值长度有限制.

三:JavaScript静态页面值传递之Window.open篇

这两窗口之间存在着关系.父窗口parent.htm打开子窗口son.htm

子窗口可以通过window.opener指向父窗口.这样可以访问父窗口的对象.

 

<inputtype=text name=maintext>

<inputtype=button value="Open">

Read.htm

<scriptlanguage="javascript" >

//window.open打开的窗口.

//利用opener指向父窗口.

varparentText = window.opener.document.all.maintext.value;

alert(parentText);

</script>

 

优点:取值方便.只要window.opener指向父窗口,就可以访问所有对象.不仅可以访问值,还可以访问父窗口的方法.值长度无限制.
缺点:两窗口要存在着关系.就是利用window.open打开的窗口.不能跨域.

JS页面间传值的更多相关文章

  1. (转)JS页面间传值

    一:JavaScript静态页面值传递之URL篇 能过URL进行传值.把要传递的信息接在URL上. 例子: 参数传出页面Post.htm—> <input type="text& ...

  2. iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值实现方法:1.通过设置属性,实现页面间传值:2.委托delegate方式:3.通知notification方式:4.block方式:5.UserDefault或者文件方式:6.单例模式 ...

  3. iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例)

    iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...

  4. 【转】iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)-- 不错

    原文网址:http://www.cnblogs.com/JuneWang/p/3850859.html iOS页面间传值的方式(NSUserDefault/Delegate/NSNotificatio ...

  5. iOS 页面间传值 之 单例传值 , block 传值

    ios 页面间传值有许多,前边已经分享过属性传值和代理传值,今天主要说一下单例传值和 block 传值 单例传值:单例模式一种常用的开发的模式,单例因为在整个程序中无论在何时初始化对象,获取到的都是同 ...

  6. iOS 页面间传值 之 属性传值,代理传值

    手机 APP 运行,不同页面间传值是必不可少,传值的方式有很多(方法传值,属性传值,代理传值,单例传值) ,这里主要总结下属性传值和代理传值. 属性传值:属性传值是最简单,也是最常见的一种传值方式,但 ...

  7. iOS页面间传值的方式 (Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)   iOS页面间传值的方式(NSUserDefault/Delegate/NSN ...

  8. iOS页面间传值的五种方式总结(Delegate/NSNotification/Block/NSUserDefault/单例)

    iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例) iOS页面间传值的方式(NSUserDefault/Delegate/NSNot ...

  9. mui框架如何实现页面间传值

    mui框架如何实现页面间传值 我的传值 listDetail = '<li class="mui-table-view-cell mui-media>">< ...

随机推荐

  1. TCP同步传送数据示例以及可能出现问题分析

    TCP传送数据可以分为同步传送和异步传送,首先这里使用了TCP的同步传送方式,学习了TCP同步传送数据的原理. 同步工作方式是指利用TCP编写的程序执行到监听或者接受数据语句的时候,在未完成当前工作( ...

  2. swift系统学习第二章

    第五节:可选类型 optional //: Playground - noun: a place where people can play import UIKit /* Swift学习第五节 可选 ...

  3. IOS 多线程编程之Grand Central Dispatch(GCD)介绍和使用 多线程基础和练习

    介绍:前面内容源自网络 Grand Central Dispatch 简称(GCD)是苹果公司开发的技术,以优化的应用程序支持多核心处理器和其他的对称多处理系统的系统.这建立在任务并行执行的线程池模式 ...

  4. CoreData的使用入门到精通

    源码下载地址: http://download.csdn.net/download/huntaiji/6664567 一,创建项目文件--选择Empty Application  起名:CoreDat ...

  5. Android沉浸式(侵入式)标题栏(状态栏)Status(三)

     Android沉浸式(侵入式)标题栏(状态栏)Status(三) 从附录文章1,2可以看到,依靠Android系统提供的标准方案,状态栏即便在透明状态下,仍然有些半透明而不是全透明.本文是And ...

  6. explicit用法

    explicit用来防止由构造函数定义的隐式转换. 要明白它的作用,首先要了解隐式转换:可以用单个实参来调用的构造函数定义了从形参类型到该类类型的一个隐式转换. 例如: class things { ...

  7. iOS-APP的沙河目录

    为了安全的缘故,一个应用只能拥有一些目录,用来写入应用的数据或者首选项参数.当一个应用安装到系统,会创建该应用的home目录.以下列出一些home目录下的主要的子目录:/AppName.app:存放应 ...

  8. 触控(Touch) 、 布局(Layout)

    1 使用触控实现一个简易的画板 1.1 问题 触控(Touch)是一个UITouch类型的对象,当用户触摸了屏幕上的视图时自动被创建,通常使用触控实现绘图.涂鸦.手写等功能.本案例使用触控实现一个简易 ...

  9. nginx+fast-cgi+c

    1. 下载fastcgi开发包,编译安装 http://www.fastcgi.com/dist/fcgi-current.tar.gz #wget http://www.fastcgi.com/di ...

  10. python内置的数据结构

    详解列表List 这里是列表对象方法的清单: list.append(x) 添加一个元素到列表的末尾.相当于a[len(a):] = [x]. list.extend(L) 将给定列表L中的所有元素附 ...