window.location.href 放置在单独的JS文件中使用时问题

场景:假设当前浏览器地址栏的地址是:http://localhost:8888/SSHBoot/tourist/homeMainAction_signInUI.do,

现在我想在点击按钮时定位到“http://localhost:8888/SSHBoot/member/adminMainAction_mainUI.do”这个地址

以下js代码是没问题,将js脚本放置到页面中

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>BootStrap学习</title>
</head>
<body>
    <input id="btnSubmit" class="btn btn-success btn-block btn-lg" type="button" value="点击">
    <script type="text/javascript" src="${basePath}/js/homeMainAction/signInUI.js" CHARSET="utf-8"></script>
   <script type="text/javascript">
        $(function($) {
            // 登录点击
            $("#btnSubmit").click(function() {
                window.location.href = "http://localhost:8888/SSHBoot/member/adminMainAction_mainUI.do";
            });
        });
    </script>
</body> </html>

但是,如果我把上面的js脚本提取出来放置到“signInUI.js”文件中,如下。这样方式就不能达到预想的效果:

浏览器地址栏中的地址就是: http://localhost:8888/SSHBoot/tourist/http://localhost:8888/member/index.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>BootStrap学习</title>
</head>
<body>
    <input id="btnSubmit" class="btn btn-success btn-block btn-lg" type="button" value="点击">
    <script type="text/javascript" src="${basePath}/js/homeMainAction/signInUI.js" CHARSET="utf-8"></script>    
</body>
</html>

signInUI.js

$(function($) {
            // 登录点击
            $("#btnSubmit").click(function() {
                window.location.href = "http://localhost:8888/SSHBoot/member/adminMainAction_mainUI.do";
            });
        });

 这个时候应该采用以下的路径样式:

$(function($) {
            // 登录点击
            $("#btnSubmit").click(function() {
                window.location.href = "../member/adminMainAction_mainUI.do";
            });
        });
原文地址:https://www.cnblogs.com/liaojie970/p/5200583.html