通过url在两个页面之间传值

今天开发遇到一个需要通过url传值才能解决的问题,就查了一下资料

一下是整理的结果:

假如需要把a页面的值传到b页面

a页面代码

<script type="text/javascript">
var id = 100;
window.location='url?id='+id;
<script/>

b页面代码


<script type="text/javascript">
$(document).ready(function(){
    $("#ex").html(location.href.split("=")[1]);//split() 方法用于把一个字符串分割成字符串数组。这里提取“=”后面的id的值
});
</script>
<span id="ex"><span/>

结果span标签的地方就会打印100

原文地址:https://www.cnblogs.com/lwx521/p/8428466.html