我的WordPress的網站有一個搜索表單,是廢話。什麼是通過JavaScript修改網址的最佳方法?
它生產這個搜索字符串:www.mysite.com/properties/?wpp_search[sort_order]=DESC&wpp_search[sort_by]=price&wpp_search[pagination]=on&wpp_search[per_page]=10&wpp_search[strict_search]=false&wpp_search[property_type]=residential_sales%2Cresidential_lettings%2Ccommercial%2Cfine_living&wpp_search[area]=&wpp_search[price][min]=&wpp_search[price][max]=&wpp_search[branch]=-1&wpp_search[bedrooms]=-1&wpp_search[department]=-1#propertycontent
什麼是最好的方式來抓住這個字符串,並改變某些方面,例如: [sort_order]=ASC
[sort_by]=price
然後重新裝入顯示新的字符串,從而改變了頁面表格輸出?
反序列化你的字符串,然後使用'location.href'應該可以工作。嘗試像'data = location.href.split('?')[1] .split('&')。map(a => a.split('='))' – somethinghere
https://developer.mozilla .org/zh-CN/docs/Web/API/URL – Bergi