-4
我想獲取當前網頁的網址(http://example.com/en-user/?1234),然後在按鈕上點擊「hi-user」更改「en-user」並轉到該頁面,因此url應該像「 http://example.com/hi-user/?1234「。提前致謝。獲取網址並點擊進行更改
我想獲取當前網頁的網址(http://example.com/en-user/?1234),然後在按鈕上點擊「hi-user」更改「en-user」並轉到該頁面,因此url應該像「 http://example.com/hi-user/?1234「。提前致謝。獲取網址並點擊進行更改
很簡單...設置按鈕上的點擊事件處理程序,獲取位置,調整字符串,設置URL。
// Get button reference
var btn = document.getElementById("btn");
// Set up click event handler
btn.addEventListener("click", function(){
// Get current URL
var url = window.location.href;
console.log(url);
// Change a portion of the string
// Obviously, change the values to suit your needs.
url = url.replace(".net", ".com");
console.log(url);
// Navigate to new URL
window.location.href = url;
});
<button id="btn">Change URL</button>
非常感謝兄弟,它爲我工作。 –
做你自己嘗試一下 –
#1的東西是不是免費的代碼編寫服務。顯示你的嘗試。 – charlietfl