2016年10月19日 星期三

[ javascript & jQuery ] 抓取URL 的值

例如:http://localhost:8082/CCCC/A1.html#tab2?text1=2222

Javascript


屬性                                       結果
------------------------------------------
window.location.host            localhost:8082
window.location.hostname    localhost
window.location.port             8082
window.location.protocol      http
window.location.pathname    A1.html
window.location.href             http://localhost:8082/CCCC/A1.html#tab2?text1=2222
window.location.hash            #tab2
window.location.search         ?text1=2222

jQuery
屬性                  結果
------------------------------------------
host                 localhost:8082
hostname        localhost
port                 8082
protocol          http:
pathname       A1.html
href                 http://localhost:8082/CCCC/A1.html#tab2?text1=2222
hash                #tab2
search             ?text1=2222
方法:var x = $(location).attr('屬性');

沒有留言:

張貼留言

影片的問題請留在影片的留言區裡。
部落格不會另外通知給我,所以很難發現你有留言。