# 第 45、46 關 window.location 小杰在 Google 時,發現了兩道題目,感覺和之後做的專題有關係,於是想要開始嘗試花兩天時間看看,一起來幫幫小杰吧! ## 45 關問題一 以下有兩顆按鈕,請使用 JavaScript 語法,操控點擊後,能夠轉址到對應網站去 ``` <button class="google">連到 Google</button> <button class="yahoo">連到 Yahoo</button> ``` ## 46 關問題一 以下有兩顆按鈕,是部落格推薦連結,請抓取 `data-id` 的值後進行轉址: 1. 點擊 Tom 時,網址為 `https://www.hexschool.com/?recommend=tom` 2. 點擊 John 時,網址為 `https://www.hexschool.com/?recommend=John` ``` <button class="google" data-id="tom">Tom 推薦六角學院</button> <button class="yahoo" data-id="John">John 推薦六角學院</button> ``` ## 46 關問題二 如果網址規則是`https://www.hexschool.com/?recommend="值"`,該如何取出 recommend 的值? 例如 `https://www.hexschool.com/?recommend=tom`,可以透過 JS,精準取出 `tom` 的值?請提供 JS 寫法。 PS:Codepen 做法是抓不到值的,需自行開 web server,或到六角官網開啟 console 面板測試 ## 完成網址 * [Tim Hsu Demo](https://hsuchihting.github.io/hexschool_JSP/jsp_index.html) * [Tim Hsu #45~#46 筆記](https://hsuchihting.github.io/javascript/20200812/659541423/) * [Tim Hsu CodePen](https://codepen.io/hnzxewqw/pen/vYGNVYZ) * [Terry Yu 45 CodePen](https://codepen.io/terry-yu-the-vuer/pen/dyMYjBB) * [Terry Yu 46 CodePen](https://codepen.io/terry-yu-the-vuer/pen/vYGNzeK) * [William Kang #44~#46 Notes](https://williamafil.github.io/notes/2020/08/14/JS-Day-44-window-location/) * [William Kang #45 & #46 CodePen](https://codepen.io/william_k/pen/eYZJVwZ?editors=1011) * [SeanLiu #45~#46 GithubPage](https://luckytiger66.github.io/JS-Practice/46/) * [SeanLiu #45~#46 原始碼](https://github.com/LuckyTiger66/JS-Practice/tree/master/46) * [Iris 小艾 45 CodePen](https://codepen.io/irisLife/pen/GRZZGzQ) * [Iris 小艾 46 CodePen](https://codepen.io/irisLife/pen/WNwwyVP) * [Ben 45~46 github](https://lu-ber.github.io/git-/level45-46.html) * [liu 44~46 CodePen](https://codepen.io/ibszthpu/pen/wvGzWaj) * [SeanChang #45 & 46 Codepen](https://codepen.io/seanchang7/pen/zYqKXVW?editors=1011)