1. 程式人生 > 其它 >html頁面跳轉

html頁面跳轉

[html]

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">test1.html</span>
[html]

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
</span>
[html]

<span style="font-family: Arial, Helvetica, sans-serif;"><!DOCTYPE html></span>
[html]

<html>
<head>
<meta charset="utf-8">
<title>test1.html頁面</title>
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
</head>
<body>
請輸入:
<input type="text" id="txta" >
<br />
第一種方式,傳輸入的值
<input type=button value="去往test2.html頁面" οnclick="tiaozhuan()" />
<script type="text/javascript">
var tiaozhuan = function(){
document.location.href ='test2.html?mydata1=' + $("#txta").val();
}
</script>
<br />
第二種方式,傳固定的值
<input type=button value="去往test2.html頁面" οnclick="document.location.href ='test2.html?mydata1=ciweigudingzhi';" />
</body>
</html>

test2.html

 

[html]

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test2.html頁面</title>
</head>
<body>
test1.html頁面傳來的值為:<input type=text id="txt1" />
<script type="text/javascript">
var txt1 = document.getElementById("txt1");
txt1.value = location.search.match(new RegExp("[\?\&]mydata1=([^\&]+)", "i"))[1];
</script>
</body>
</html>

————————————————
版權宣告:本文為CSDN博主「@.YX」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/woniu0929/article/details/84349512

搜尋

複製