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">點擊</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"> //獲取 上一個搜索頁面?zhèn)鱽淼膮?shù) var searchUrl = window.location.href; var searchData = searchUrl.split("="); //截取 url中的“=”,獲得“=”后面的參數(shù) var searchText = decodeURI(searchData[1]); //decodeURI解碼 $(".keyword1").val(searchText); </script> </body> </html>
運行結(jié)果:
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請關(guān)注Gxl網(wǎng)其它相關(guān)文章!
推薦閱讀:
vue渲染時閃爍應(yīng)如何處理
JS實現(xiàn)左右列表互相調(diào)換功能
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com