码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-08-24 10:43:53      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:name   路径   ref   time   跳转   eth   splay   页面跳转   document   

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实现页面跳转的两种方式

标签:name   路径   ref   time   跳转   eth   splay   页面跳转   document   

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

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