# Week 6(10/16):Java Script(2) ## 解析網址參數 在網址中添加`?XXX=你要傳遞的字串`即可設定參數。 P.S.設定多個參數:用`?XXX=…&YYY=…&…&…`這種形式) ```html= <!DOCTYPE html> <html> <head> <script type="text/javascript"> // 取得網址裡的參數 function GetUrlVar(VarName) { //正規表示式 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + VarName + "=([^&#]*)"; var regex = new RegExp(regexS); //令為可處理正規表示式的物件 var results = regex.exec(window.location.href);//處理正規表示式 if (results == null) return ""; else return results[1]; } // 要先取得網址裡的路徑起點終點經緯度參數 var X = decodeURIComponent(GetUrlVar('XXX')); //解碼字串 alert(X); </script> </head> <body> </body> </html> ``` ### decodeURIComponent() method 用來解碼字串(使其由代碼轉為文字)。 EX:   詳細介紹:https://www.w3schools.com/jsref/jsref_decodeuricomponent.asp ### 正規表示式 用特定符號規定其形態,以取得所要內容。 詳細介紹:https://w3schools.com/js/js_regexp.asp ## 發布網頁 入門可先用[netlify](https://www.netlify.com/)。 !!!主網頁名字要設為index ## google map網址編輯 用`http://maps.google.com.tw/maps?f=q&hl=zh-TW&q=經緯度位置`即可去到所需google map頁面;用`http://maps.google.com.tw/maps?saddr=起點經緯度位置&daddr=終點經緯度位置`可出現路線。 ## 在網站中開其他網站 利用open() method。 詳細說明:https://www.w3schools.com/jsref/met_win_open.asp
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up