首页 > Web开发 > 详细

js实现页面跳转的两种方式

时间:2017-08-24 09:36:22      阅读:165      评论:0      收藏:0      [点我收藏+]

CreateTime--2017年8月24日08:13:52
Author:Marydon

js实现页面跳转的两种方式

方式一:

  window.location.href = url

说明:我们常用来在js中实现页面跳转的方法,使用get方式发送请求,传参有限

更多介绍,见文章:js操作当前窗口  

方式二:

  通过POST请求实现页面跳转

/**
 * 发送POST请求跳转到指定页面
 * @param URL
 *         跳转路径
 * @param PARAMS
 *        参数:格式-JSON对象
 */
function httpPost(URL, PARAMS) {
    var temp = document.createElement("form");
    temp.action = URL;
    temp.method = "post";
    temp.style.display = "none";
    for (var x in PARAMS) {
        var opt = document.createElement("textarea");
        opt.name = x;
        opt.value = PARAMS[x];
        temp.appendChild(opt);
    }
    document.body.appendChild(temp);
    temp.submit();
    return temp;
}

 

 

 

js实现页面跳转的两种方式

原文:http://www.cnblogs.com/Marydon20170307/p/7421228.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!