比如当前的url为localhost:8080/user/login
如果我们需要跳转回localhost:8080/user/admin
1.我们可以利用http的重定向来跳转
window.location.replace("/user/admin")
2.使用href来跳转
window.location.href = " http://www.baidu.com "
3.使用jQuery的属性替换方法
3.1 $(location).attr('href', '/user/admin')
3.2 $(window).attr('location','/user/admin')
3.3 $(location).prop('href', '/user/admin')
至于为什么可以这么跳转,大概是因为相对路径的原因吧
这个直接javascript就可以实现的:
<a href="#" id="aid">百度</a><button id="btn">改变herf</button>
<script>
document.getElementById("btn").addEventListener("click",change)
function change()
{
document.getElementById("aid").href="http://www.baidu.com"
}
</script>
以上代码即可实现。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)