2017-07-15 65 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

非常感谢兄弟,它为我工作。 –