码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-02-19 14:04:21      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

场景:假设当前浏览器地址栏的地址是: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";
            });
        });

 

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

标签:

原文地址:http://www.cnblogs.com/liaojie970/p/5200583.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!