数码资讯
Javascript获取html静态页面参数传递值的一个示例。
只要把代码嵌入到页面文件中,就可以查看一下我的代码。 一例 使用正则表达式获得 复制代码代码如下所示: 无功locstring =字符串(窗口。文件位置。href); 功能getquerystr(STR){ VaR RS = new RegExp((^ |)+力量+=({ ^ } *)(|美元) 如
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
只要把代码嵌入到页面文件中,就可以查看一下我的代码。
一例
使用正则表达式获得
复制代码代码如下所示:
无功locstring =字符串(窗口。文件位置。href);
功能getquerystr(STR){
VaR RS = new RegExp((^ |)+力量+=({ ^ } *)(|美元)
如果(TMP = RS){
返回TMP { 2 };
}
找不到参数
返回;
}
调用方法
复制代码代码如下所示:
document.getelementbyid(用户)。值= getquerystr(用户);
document.getelementbyid(密码)。值= getquerystr(密码);
document.getelementbyid(sysno)。值= getquerystr(sysno );
在两例
使用拆分函数用参数切割数组
复制代码代码如下所示:
URLInfo = / / window.location.href;获取当前页面的URL
获取URL / / len = urlinfo.length长度;
(偏移= URLInfo。指标); / /套的字符串开始的参数
newsidinfo = urlinfo.substr(偏移,Len) / /移除参数字符串会像ID = 1弦
newsids = newsidinfo.split(=); / /参数根据分割=字符串
Newsid=newsids{1}; / / get the parameter value
警报(参数值要通过+ NewSID);
但是,我们必须记住,这个方法只对有参数的URL有用。如果另一方使用POST方法传输参数,URL将不包含参数,因此该技术只对获取带有指定参数的方法或URL有用。
下面是一个完整的例子
aa.htm是浸润和渗出的接口参数
bb.htm是参数接收处理接口
aa.htm
复制代码代码如下所示:
U3000
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
函数提交()
{
VaR input1 = document.getelementbyid(inputid );
Window.open(BB。htminputstr = + input1。值); / /争论
}
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
Bb.htm:
U3000 U3000
U3000 U3000
U3000 U3000
获取参数的方法
无功要求=
{
查询:功能(Val)
{
VaR的URI = window.location.search;
var = new RegExp(+价值+=({ ^ } *)
返回((uri.match(重新))(uri.match(重新){ 0 }。substr(val.leng TH + 1)):空);
}
}
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
调用方法参数
VAR RT = request.querystring(inputstr );
警报(RT);
U3000 U3000
U3000 U3000
U3000 U3000
bb.htm
复制代码代码如下所示:
U3000 U3000
测试
U3000 U3000
U3000 U3000
<!——
var请求{ {
查询:功能(Val){
VaR的URI = window.location.search;
var = new RegExp(+价值+=({ ^ } *)
返回((uri.match(重新))(uri.match(重新){ 0 }。substr(val.leng TH + 1)):空);
}
}
创建一个request.querystring();
var b = request.querystring(B);
var c = request.querystring(C);
如果((a)!NULL)){其他}参数为空}
如果((b)!= NULL))
如果((c)!NULL))
document.writeln(参数:+);
document.writeln(B参数:+ B);
document.writeln(参数C:+ C);
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
请输入参数值:
U3000 U3000
document.writeln(:);
document.writeln(B);
document.writeln(C);
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
一例
使用正则表达式获得
复制代码代码如下所示:
无功locstring =字符串(窗口。文件位置。href);
功能getquerystr(STR){
VaR RS = new RegExp((^ |)+力量+=({ ^ } *)(|美元)
如果(TMP = RS){
返回TMP { 2 };
}
找不到参数
返回;
}
调用方法
复制代码代码如下所示:
document.getelementbyid(用户)。值= getquerystr(用户);
document.getelementbyid(密码)。值= getquerystr(密码);
document.getelementbyid(sysno)。值= getquerystr(sysno );
在两例
使用拆分函数用参数切割数组
复制代码代码如下所示:
URLInfo = / / window.location.href;获取当前页面的URL
获取URL / / len = urlinfo.length长度;
(偏移= URLInfo。指标); / /套的字符串开始的参数
newsidinfo = urlinfo.substr(偏移,Len) / /移除参数字符串会像ID = 1弦
newsids = newsidinfo.split(=); / /参数根据分割=字符串
Newsid=newsids{1}; / / get the parameter value
警报(参数值要通过+ NewSID);
但是,我们必须记住,这个方法只对有参数的URL有用。如果另一方使用POST方法传输参数,URL将不包含参数,因此该技术只对获取带有指定参数的方法或URL有用。
下面是一个完整的例子
aa.htm是浸润和渗出的接口参数
bb.htm是参数接收处理接口
aa.htm
复制代码代码如下所示:
U3000
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
函数提交()
{
VaR input1 = document.getelementbyid(inputid );
Window.open(BB。htminputstr = + input1。值); / /争论
}
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
Bb.htm:
U3000 U3000
U3000 U3000
U3000 U3000
获取参数的方法
无功要求=
{
查询:功能(Val)
{
VaR的URI = window.location.search;
var = new RegExp(+价值+=({ ^ } *)
返回((uri.match(重新))(uri.match(重新){ 0 }。substr(val.leng TH + 1)):空);
}
}
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
调用方法参数
VAR RT = request.querystring(inputstr );
警报(RT);
U3000 U3000
U3000 U3000
U3000 U3000
bb.htm
复制代码代码如下所示:
U3000 U3000
测试
U3000 U3000
U3000 U3000
<!——
var请求{ {
查询:功能(Val){
VaR的URI = window.location.search;
var = new RegExp(+价值+=({ ^ } *)
返回((uri.match(重新))(uri.match(重新){ 0 }。substr(val.leng TH + 1)):空);
}
}
创建一个request.querystring();
var b = request.querystring(B);
var c = request.querystring(C);
如果((a)!NULL)){其他}参数为空}
如果((b)!= NULL))
如果((c)!NULL))
document.writeln(参数:+);
document.writeln(B参数:+ B);
document.writeln(参数C:+ C);
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
请输入参数值:
U3000 U3000
document.writeln(:);
document.writeln(B);
document.writeln(C);
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
U3000 U3000
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。