文章出處
文章列表
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 }
文章列表
全站熱搜