2017-07-15 70 views

回答

0

很簡單...設置按鈕上的點擊事件處理程序,獲取位置,調整字符串,設置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>

+0

非常感謝兄弟,它爲我工作。 –