1. 程式人生 > >html 頁面之間跳轉和傳值

html 頁面之間跳轉和傳值


從a.html 跳轉到b.html 並吧 a.html 的值傳入b.html

a.html
<html>
 <head>
  <title> New Document </title>
    <script>
      function   to (){
        var  getval =document.getElementById("cc").value;
        document.location.href("b.html?cc="+getval);   
      }
    </script>
 </head>
 <body>
  <input type="text" id ="cc" > <input type="button"  value="a"  onclick="to()" >
 </body>
</html>

b.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
 <title> New Document </title>
 <script>  
  var thisURL = document.URL;  
  var  getval =thisURL.split('?')[1];
  var showval= getval.split("=")[1];
  function  showvalf(){
     alert(showval);
     document.getElementById('ee').value=showval;
  }
</script>
 </head>
 <body onload="showvalf()">
  <input type="text"  id ="ee" />
 </body>
</html>