html与html传值(html之间如何传值)

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

今天给各位分享html与html传值的知识,其中也会对html之间如何传值进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

html 页面间传值

用服务器语言来获取传递的参数如a.html有如下组件from action="b.html" method="post"input type="text" value="aaaaa" name="txt"/form那么你可以在b.html中用%String Val=(String)request.getParameter("txt");out.print(Val);%这样你就可以获取到a.html页面中的文本框组件的值aaaaa

怎么在2个html页面间传值

html是静态页面,可以使用url链接传值,比如a.html和b.html两个页面

a.html中有一个链接

1

a href="b.html?x=2y=3"进入b.html/a

可以使用到js,如下:

a.htm:

1

2

3

4

form action="b.htm"

input name="q" type="text" value="" /

input type="submit" value="提交" id="" /

/form

b.htm

html

body

div id="qbox"/div

script type="text/javascript"

function getArgs() {

var args = {};

var query = location.search.substring(1);

// Get query string

var pairs = query.split("");

// Break at ampersand

for(var i = 0; i pairs.length; i++) {

var pos = pairs[i].indexOf('=');

// Look for "name=value"

if (pos == -1) continue;

// If not found, skip

var argname = pairs[i].substring(0,pos);// Extract the name

var value = pairs[i].substring(pos+1);// Extract the value

value = decodeURIComponent(value);// Decode it, if needed

args[argname] = value;

// Store as a property

}

return args;// Return the object

}

var str =getArgs();

alert(str['q']);//和input的name对应取值,

document.getElementById("qbox").innerHTML = str['q'];//然后赋值给DIV

/script

/body

/html

希望能帮到你哦!

两个html的页面之间怎么传递参数啊

1、首先在电脑打开eclipse软件。然后创建int参数age,赋值为21。代码:int age=21。

2、参见静态方法addAge(int a),内有参数a。

3、然后在addAge方法中,增加a增值的代码。

4、然后再从addAge方法中,输出a增加后的值。

5、然后在main方法中,将age的值传递给a。

6、然后在main方法中,输出数值传递之后的效果。

html如何传值

html静态页面间传值有以下三种方法:

方法一:

下面是javascrīpt的一种实现方法, 这个函数是通过window.location.href中的分割符获得各个参数。 有了这个函数,就可以在页面之间传递参数了。

/* *函数功能:从href获得参数 *sHref: ;arg2=re *sArgName:arg1, arg2 *return: the value of arg. d, re */

function GetArgsFromHref(sHref, sArgName)

{

var args = sHref.split("?");

var retval = "";

if(args[0] == sHref) /*参数为空*/

{

return retval; /*无需做任何处理*/

}

var str = args[1];

args = str.split("");

for(var i = 0; i args.length; i ++)

{

str = args[i];

var arg = str.split("=");

if(arg.length = 1) continue;

if(arg[0] == sArgName)

retval = arg[1];

}

return retval;

}

方法二:

html地址传递参数进行其他事情.

scrīpt /* 用途: 接收地直栏参数 取id=1 根据ID的值 */

urlinfo=window.location.href; //获取当前页面的url

len=urlinfo.length;//获取url的长度

offset=urlinfo.indexOf("?"); //设置参数字符串开始的位置 newsidinfo=urlinfo.substr(offset,len)//取出参数字符串 这里会获得类似“id=1”这样的字符串

newsids=newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割 newsid=newsids[1];//得到参数值

newsname=newsids[0];//得到参数名字

/scrīpt

方法三:

做中英转换的时候,要准确的获取参数并取出,所以做了一个简单的html中用js获取当取地址栏的一个Object。

里面有三个方法:

1、request.QueryString("参数")//获取指定参数,返回字符串;

2、request.QueryStrings();//获取全部参数,并返回数组;

3、 request.setQuery("参数","参数的值");//如果当前地址栏有此参数,那么将更新此参数,否则返回一个新的地址栏参数字符串。

例如:当前地址栏参数字符串为:?name=asite=never_online alert(request.setQuery("name","blueDestiny")) 如果地址栏参数中有"name",那么返回?name=blueDestinysite=never_online setQuery 方法有自动追加参数的功能。如:当前地址栏参数字符串为:?site=never_online alert(request.setQuery("name","blueDestiny")) 则返回?site=never_onlinename=blueDestiny 同理,如果地址栏没有参数,也会自动追加参数 alert(request.setQuery("name","blueDestiny")) 返回?name=blueDestiny

html如何两个页面之间相互传递数据

1、使用表单传递数据

两个html页面,a.html,b.html想。把a.html中的表单form中的id和pwd传到b.html中

form action="b.html" method="post" name="formName"/form

要用form表单配合后台语言来传,发送类型POST和GET看你需求要换。

2、使用JS传递接收数据

html1 input type="text" value="nihao" id="text"/html

html2/html

如何用JS把HTML1中的text属性值nihao 传递给html2  在HTML2中有怎样用JS接收传递过来的数据并显示。

html1a href="html2.html?word=nihao"a

html2

js代码:

var str=location.href.search;//取地址参数部分

word = str.sbustr(str.indexOf('=')+1);

word就可以获得地址中传递的参数了;如果有多个参数可以用split函数

3、两个纯Html之间的传值实例

index1.htm页面

HTML

    HEAD

    TITLE New Document /TITLE//标题

        SCRIPT LANGUAGE="JavaScript" //调用JavaScript方法   

        function show(){       

         var result = document.getElementByIdx("name").value;  //获取值.     

          location.href="index2.htm?name="+result;  //  链接跳转

                      }

        /SCRIPT

          style.input7 {color: #999;width:145px;height:20px;border: 1px solid #CCCCCC; font-size:12px;background-color: #fff;}//css样式

          /style

    /HEAD

    BODY

    input type="text" id="name" class="input7"input type="button" value="OK" onclick="show()"///输出

    /BODY

/HTML

index2页面:

HTML

HEAD

TITLE New Document /TITLE

SCRIPT LANGUAGE="JavaScript"

function getvalue(name){    

    var str=window.location.search;   //location.search是从当前URL的?号开始的字符串     

    if (str.indexOf(name)!=-1)//判断是否收到值

     {                

     var pos_start=str.indexOf(name)+name.length+1;  //解析获取值   

     var pos_end=str.indexOf("",pos_start);        

     if (pos_end==-1){           

      alert( str.substring(pos_start));  //输出      

                      }

     else{           

      alert("没有此值~~");    

          }  

      }

/SCRIPT

/HEAD

BODY

input type="button" onclick="getvalue('show')" value="GetValue"/

/BODY

/HTML

两个html页面之间怎么传递参数值

使用Cookie传递参数 ,a页面保存Cookie,b页面读取,代码如下:

a页面

html

head

titlea/title

style type="text/css"

* {margin:0}

body {text-align:center;min-width:760px}

div {padding:3px 3px 3px 3px}

#main {width:720px;margin:0 auto;text-align:left;margin-top:30px}

#main div span {width:50px}

/style

script type="text/javascript"

/***

* @param {string} cookieName Cookie名称

* @param {string} cookieValue Cookie值

* @param {number} nDays Cookie过期天数

*/

function SetCookie(cookieName,cookieValue,nDays) {

    /*当前日期*/

    var today = new Date();

    /*Cookie过期时间*/

    var expire = new Date();

    /*如果未设置nDays参数或者nDays为0,取默认值1*/

    if(nDays == null || nDays == 0) nDays = 1;

    /*计算Cookie过期时间*/

    expire.setTime(today.getTime() + 3600000 * 24 * nDays);

    /*设置Cookie值*/

    document.cookie = cookieName + "=" + escape(cookieValue)

        + ";expires=" + expire.toGMTString();

}

function login() {

    var username = $("user").value;

    var password = $("pass").value;

    /*是否选中7天内无需登录*/

    var save = $("save").checked;

    if(username=="abc"  password=="abc") {

        if(save) SetCookie("username",username,7);

        else SetCookie("username",username,1);

        /*跳转到ex8.html页面*/

        document.location = "b.htm";

    } else {

        alert("用户名或密码错误!");

    }

}

function $(id) {

    return document.getElementById(id);

}

/script

/head

body

    div id="main"

        divspan用户名:/spaninput type="text" id="user" //div

        divspan密码:/spaninput type="password" id="pass" //div

        div

            input type="checkbox" id="save" /

            7天内无需登录

            input type="button" onclick="login()" value="登录" /

        /div

    /div

/body

/html

b页面

html

head

titleb/title

script type="text/javascript"

/***

*读取指定的Cookie值

*@param {string} cookieName Cookie名称

*/

function ReadCookie(cookieName) {

    var theCookie = "" + document.cookie;

    var ind = theCookie.indexOf(cookieName);

    if(ind==-1 || cookieName=="") return "";

    var ind1 = theCookie.indexOf(';',ind);

    if(ind1==-1) ind1 = theCookie.length;

    /*读取Cookie值*/

    return unescape(theCookie.substring(ind+cookieName.length+1,ind1));

}

function $(id) {

    return document.getElementById(id);

}

function init() {

    var username = ReadCookie("username");

    if(username  username.length0) {

        $("msg").innerHTML = "h1欢迎光临," + username + "!/h1";

    } else {

        $("msg").innerHTML = "a href='a.htm'请登录/a";

    }

}

/script

/head

body onload="init()"

    div id="msg"/div

/body

/html

效果如下:

html与html传值的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于html之间如何传值、html与html传值的信息别忘了在本站进行查找喔。

发布于 2023-04-09 02:04:03
收藏
分享
海报
30
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了