小杰在 Google 時,發現了兩道題目,感覺和之後做的專題有關係,於是想要開始嘗試花兩天時間看看,一起來幫幫小杰吧!
以下有兩顆按鈕,請使用 JavaScript 語法,操控點擊後,能夠轉址到對應網站去
<button class="google">連到 Google</button>
<button class="yahoo">連到 Yahoo</button>
以下有兩顆按鈕,是部落格推薦連結,請抓取 data-id
的值後進行轉址:
https://www.hexschool.com/?recommend=tom
https://www.hexschool.com/?recommend=John
<button class="google" data-id="tom">Tom 推薦六角學院</button>
<button class="yahoo" data-id="John">John 推薦六角學院</button>
如果網址規則是https://www.hexschool.com/?recommend="值"
,該如何取出 recommend 的值?
例如 https://www.hexschool.com/?recommend=tom
,可以透過 JS,精準取出 tom
的值?請提供 JS 寫法。
PS:Codepen 做法是抓不到值的,需自行開 web server,或到六角官網開啟 console 面板測試