文章出處

1.通過URL傳遞參數

傳遞參數頁

 1      function setCity()
 2 
 3      {
 4 
 5          var str = document.getElementById("cityName");
 6 
 7          if (str.value == null || str.value == "") {
 8 
 9              alert('請輸入到達城市!');
10 
11              return;
12 
13          }
14 
15          else{
16 
17               var url="5.html?cityName="+str.value;
18 
19               alert(url);
20 
21               var urlInfo=encodeURI(url);
22 
23               window.location=urlInfo;
24 
25          }
26 
27 }

 

<div class="main1of2" >到達城市:<input type="text" id="cityName"  /></div>

 

<input type="image" src="../images/TJ.png" onmousedown="setCity()" onclick="setCity()" style="border: 0px;"/>

接受參數頁面

 1    function load()
 2 
 3    {
 4 
 5      var urlinfo = window.location.href;                                               //獲取url
 6 
 7      var str = urlinfo.split("?")[1].split("=")[1];                                      
 8 
 9      //拆分url得到“=”號后面的值(先用split("?")[1]得到?號以后的值,再用split("=")[1]得到等號后面的值,split從0開始計數)
10 
11     var name = decodeURI(str);
12 
13   //decodeURI解碼
14 
15     var imgUrl="../images/" + name + ".png";
16 
17     document.getElementById("imgBanci").src=imgUrl;
18 
19      }

 

<img id="imgBanci" />

2.通過剪貼板傳遞參數

     傳遞參數頁:

    

 1  function setCity()
 2 
 3      {
 4 
 5          var str = document.getElementById("cityName");
 6 
 7          if (str.value == null || str.value == "") {
 8 
 9              alert('請輸入到達城市!');
10 
11              return;
12 
13          }
14 
15          else {
16 
17              clipboardData.clearData("Text");
18 
19                    //清空剪貼板中“Text“格式的所有內容
20 
21              clipboardData.setData("Text",str.value);
22 
23                    //設置剪貼板中“Text“格式的內容
24 
25              window.location = "5.html";
26 
27                    //頁面跳轉
28 
29          }

 

     接受參數頁

 1      function load()
 2 
 3      {
 4 
 5          var str = clipboardData.getData("Text");
 6 
 7          //訪問剪貼板中的“Text“格式的內容
 8 
 9          var imgUrl = "../images/" + str + ".png";
10 
11          //生成圖片路徑
12 
13          document.getElementById("imgBanci").src = imgUrl;
14 
15      }

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()