溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

jQuery實(shí)現(xiàn)瀏覽器之間跳轉(zhuǎn)并傳遞參數(shù)功能【支持中文字符】

發(fā)布時(shí)間:2020-09-02 05:04:06 來(lái)源:腳本之家 閱讀:258 作者:郭浩326 欄目:web開(kāi)發(fā)

本文實(shí)例講述了jQuery實(shí)現(xiàn)瀏覽器之間跳轉(zhuǎn)并傳遞參數(shù)功能。分享給大家供大家參考,具體如下:

one.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.slim.js"></script>
</head>
<body>
<input type="text" class="keyword"/>
<button id="searchBtn">點(diǎn)擊</button>
<script type="text/javascript">
  $("#searchBtn").click(function() {
    var searchText = jQuery.trim($(".keyword").val());
    var searchUrl = encodeURI("two.html?searchText=" + searchText); //使用encodeURI編碼
    location.href = searchUrl;
  })
</script>
</body>
</html>

two.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.slim.js"></script>
</head>
<body>
<input type="text" class="keyword1"/>
<script type="text/javascript">
  //獲取 上一個(gè)搜索頁(yè)面?zhèn)鱽?lái)的參數(shù) 
  var searchUrl = window.location.href;
  var searchData = searchUrl.split("="); //截取 url中的“=”,獲得“=”后面的參數(shù)
  var searchText = decodeURI(searchData[1]); //decodeURI解碼
  $(".keyword1").val(searchText);
</script>
</body>
</html>

運(yùn)行結(jié)果:

jQuery實(shí)現(xiàn)瀏覽器之間跳轉(zhuǎn)并傳遞參數(shù)功能【支持中文字符】

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery常見(jiàn)事件用法與技巧總結(jié)》、《jQuery form操作技巧匯總》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》及《jquery選擇器用法總結(jié)》

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI