在我的项目1中写到过网页之间传值,但是那种方式在andriod4.0和以下版本就传不过去了,于是乎,就打起了HTML5本地存储的注意。大家看一下代码就知道什么意思了:
发送数据页面:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript"> window.onload = function() { } function tijiao() { var zhi1 = document.getElementById("zhi1").value; var zhi2 = document.getElementById("zhi2").value; localStorage.setItem("1", zhi1); localStorage.setItem("2", zhi2); } </script> </head> <body> 传输数据1: <input type="text" name="zhi1" id="zhi1" value="123" /> <br />传输数据2: <input type="text" name="zhi2" id="zhi2" value="234" /> <a href="jieshouyemian.html"><button id="myButton" onclick="tijiao()">提交跳转传值</button></a> </body> </html>
接收数据页面:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="js/jquery.min.js" ></script> <script type="text/javascript"> window.onload=function(){ if(window.localStorage){ alert("支持;"); }else{ alert("不支持"); } var a=localStorage.getItem("1"); var b=localStorage.getItem("2"); document.getElementById("jieshouzhi1").value=a; document.getElementById("jieshouzhi2").value=b; /*$("#jieshouzhi1").val(a); $("#jieshouzhi2").val(b);*/ } </script> </head> <body> 接收到的值1:<input type="text" name="jieshouzhi1" id="jieshouzhi1" value="null" /><br /> 接收到的值2:<input type="text" name="jieshouzhi2" id="jieshouzhi2" value="null" /> </body> </html>
看看适应性如何了,再不行,就只能在想别的办法了,,哎。。
时间: 2024-10-26 06:11:51