要在 HTML 中使用 script 标签跳转到同一路径下的子路径,可以使用如下方法:
使用相对路径:在 script 标签中使用相对路径,如 "./子路径/文件名.html"。
使用绝对路径:在 script 标签中使用绝对路径,如 "/子路径/文件名.html"。
例如,如果要跳转到同一路径下的子路径 "subpath" 中的文件 "page.html",可以使用如下代码:
<script>
window.location.href = "./subpath/page.html";
</script>
或者
<script>
window.location.href = "/subpath/page.html";
</script>
注意:使用 script 标签跳转页面会立即跳转,并且无法使用浏览器的后退按钮返回到之前的页面。因此,建议使用其他方式(例如 a 标签或者 form 标签)来实现跳转。