您好,登錄后才能下訂單哦!
本文實(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é)果:
更多關(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ì)有所幫助。
免責(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)容。