我有
一个按钮
<button id="next" onclick="inlastSegment()">下一步</button>
和一个URL
http://localhost:8888/projects/oop/2
我的目标
是当我点击那个按钮时,我想要增加我的URL的最后一个部分。
例如
http://localhost:8888/projects/oop/3
http://localhost:8888/projects/oop/4
http://localhost:8888/projects/oop/5
我已经尝试过
<script type="text/javascript">
var href = location.href; // http://localhost:8888/projects/oop/2
var lastSegment = window.location.pathname.split('/').pop();
console.log(lastSegment); //2
function inlastSegment() {
lastSegment = (parseInt(lastSegment)+1);
console.log(lastSegment); //3
//Stuck
}
</script>
我有点困惑,希望您能给一些提示/建议,非常感谢。
在PHP中是否有可能实现这个功能?只是出于好奇。
window.location.replace()
方法。 - hindmost