Javascript 更改当前URL,然后加载
我希望jquery找到并更改您正在访问的当前URL,然后加载新的URL。假设jquery应该在单击后将当前的“index.html”更改为“indexalt.html”,然后加载它。我的想法是使用document.URL获取当前URL,然后在末尾切掉“.html”,并在字符串中添加例如“alt.html”。我对jquery非常陌生,无法让它工作。我的脚本中可能会有很多错误:Javascript 更改当前URL,然后加载,javascript,jquery,string,url,slice,Javascript,Jquery,String,Url,Slice,我希望jquery找到并更改您正在访问的当前URL,然后加载新的URL。假设jquery应该在单击后将当前的“index.html”更改为“indexalt.html”,然后加载它。我的想法是使用document.URL获取当前URL,然后在末尾切掉“.html”,并在字符串中添加例如“alt.html”。我对jquery非常陌生,无法让它工作。我的脚本中可能会有很多错误: $("#contact").on('click', function() { var url=document.URL(s
$("#contact").on('click', function() {
var url=document.URL(str.slice(-7));
.load("url +"alt.html"");
如果有人能告诉我怎么做,怎么把它完整地写下来,我将不胜感激。谢谢
location.href
返回页面的URL。所以,你可以这样做
$("#contact").on("click", function() {
// Slicing 5 characters from the URL.
const url = location.href.slice(0, -5)
// Simply load the URL
location.href = url + "alt.html"
})
window.location=window.location.slice(0,-5)+'alt.html'
document.URL???