javascript实现页面跳转功能,参数怎么传递?

JavaScript022

javascript实现页面跳转功能,参数怎么传递?,第1张

1.设置url

// 设置当前urlvar list_url = '/document/order/default.php?page=' + page_nums + '&'+ $("#form1").serialize()var e_list_url = encodeURIComponent(list_url)$("#list_url").val(e_list_url)

2.传递url

var list_url = $('#list_url').val()

window.location.href='/document/order/view.php?order_id='+order_id+'&action=edit&handler=admin&list_url='+list_url

3.解析url并跳转

var list_url = '<?php echo $list_url?>'

d_list_url = decodeURIComponent(list_url)window.location.href = d_list_url

这样就能实现,参数不丢失了。主要就是页码和筛选条件。

纯js页面跳转要传复杂数据不好做,要用localStorage,这个东东在各浏览器中是不一样的。

比较好的方法就是,在跳转链接中加上一些标志参数,如对象ID之类,直接由服务器生成新页面内容或者转到新页面后由页面从服务器重新ajax取数据。

<script>

//用GET传值

//跳转到指定网址

localtion="www.xxx.com?name=name"

//获取url

var url = window.location

//正则表达式

var regx = /name=.+/

//正则匹配

var name = regx.exec(url)

alert(name)

</script>