js操作地址栏

//判断地址里是否有?号,如果没有就从最后一个/截到最后,如果有?就从最后一个/截至?号处
listTable.url = location.href.lastIndexOf("?") == -1 ? location.href.substring((location.href.lastIndexOf("/")) + 1) : location.href.substring((location.href.lastIndexOf("/")) + 1, location.href.lastIndexOf("?"));
listTable.url += "?is_ajax=1";
console.log(listTable.url );

例子:
地址栏里的地址为:http://localhost/test/9.html

结果为:

9.html??is_ajax=1

地址栏里的地址为:http://localhost/test/9.html?a=123

结果为:

9.html??is_ajax=1

posted @ 2018-10-15 13:29  HaimaBlog  阅读(433)  评论(0编辑  收藏  举报