怎么在JS里加这个URL

JavaScript030

怎么在JS里加这个URL,第1张

使用js对当前的URL进行操作,可以使用内置对象window.location;

window.location的用法:

window.location.replace(url):用传入的URL字符串替代当前的URL,该方法会将历史记录中的URL一并替换掉,也就是说,这个方法会覆盖之前的历史记录;

window.location.reload():重新加载当前URL,相当于刷新;

window.location.assign(url):加载传入的URL,该方法不会覆盖之前的历史记录;

你试试这个看看吧<a href="javascript:void(0)" id='test' onclick="tiao()"><%=username%></a><script>//JS里添加function tiao(){var str = "ChgUser.do?userid=<%=uid%>&role=" + document.getElementById("Select").valuewindow.location.href = str}</script>

你的url要显示在什么地方?

如果是显示在最后,可以在js里面追加html

比如:

var url = document.createElement('a')

url.href = 'http://xxxx'

url.innerText = url.href

document.body.appendChild(url)