当前位置: 首页 > news >正文

网站 备案 中国 名字新东方小吃培训价格表

网站 备案 中国 名字,新东方小吃培训价格表,洛阳市建设工程安全监督网站,为什么我的网站备案通过还是显示未备案HTML页面之间的数据传递 1.通过window.location.href发送,location.search接收2.通过window.location.open()发送 1.很多小伙伴在做页面时,有没有想过两个页面之间如何在跳转的同时,还能够传递一些数据过去   2.跳转页面时,我们…

HTML页面之间的数据传递

    • 1.通过window.location.href发送,location.search接收
    • 2.通过window.location.open()发送

  1.很多小伙伴在做页面时,有没有想过两个页面之间如何在跳转的同时,还能够传递一些数据过去
  2.跳转页面时,我们首先想到的是利用a标签进行跳转。
  3.一般我们通过a标签的方式只能进行页面之间的跳转,而无法将想要的数据传递过去。
  4.接下来将讲解两个页面之间如何进行数据的传递。

1.通过window.location.href发送,location.search接收

  1这里我们一般将window.location.href绑定在点击事件上进行跳转,它类似于a标签,但是可以传递参数。
01.html页面代码如下

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>button{width: 300px;height: 300px;position: absolute;left: 50%;top: 50%;transform: translate(-50%,-50%);background-color: aquamarine;}</style>
</head>
<body><h1 style="text-align: center;">01.html</h1><button>点击我跳转</button>
</body>
<script>let button=document.getElementsByTagName("button")[0]button.onclick=function(){//路径+参数名+参数值window.location.href = './02.html?'+'uname='+'zhangsan'//2.下面这种方式将数据进行编码,可以传递中文不出现乱码,推荐// window.location.href = encodeURI('./02.html?uname=哈哈');}
</script>
</html>

  1这里我们利用location.search来接收数据

02.html页面代码如下

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>button {width: 300px;height: 300px;position: absolute;left: 50%;top: 50%;transform: translate(-50%, -50%);background-color: aquamarine;}</style>
</head><body><h1 style="text-align: center;">02.html</h1><button>点击我,弹出接收信息</button>
</body>
<script>var name = location.search;// var name = decodeURI(document.URL)//获取到编码的数据并进行解码,推荐//获取到的数据其实是  ?uname=zhangsan'//下面是对数据进行处理name=name.slice(name.indexOf("=")+1)console.log(name);var button = document.querySelector("button");button.onclick = function () {alert(name)}
</script></html>

效果如下:
在这里插入图片描述

2.通过window.location.open()发送

如果是希望打开一个新页面,而不是改变当前的页面,那么window.location.href就不适用了,此时,我们需要借助于window.open()来实现 ,它是用来打开一个新的浏览器窗口或查找一个已命名的窗口。

  window open()用法
01.html页面代码如下

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>button{width: 300px;height: 300px;position: absolute;left: 50%;top: 50%;transform: translate(-50%,-50%);background-color: aquamarine;}</style>
</head>
<body><h1 style="text-align: center;">01.html</h1><button>点击我跳转</button>
</body>
<script>let button=document.getElementsByTagName("button")[0]button.onclick=function(){//路径+参数名+参数值  使用encodeURI进行编码,可以传中文window.open(encodeURI('./02.html?'+'uname='+'哈哈哈'))}
</script>
</html>

02.html页面代码如下

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>button {width: 300px;height: 300px;position: absolute;left: 50%;top: 50%;transform: translate(-50%, -50%);background-color: aquamarine;}</style>
</head><body><h1 style="text-align: center;">02.html</h1><button>点击我,弹出接收信息</button>
</body>
<script>//对数据进行解码var name= decodeURI(document.URL)//获取到的数据其实是  ?uname=哈哈哈'//下面是对数据进行处理name=name.slice(name.indexOf("=")+1)var button = document.querySelector("button");button.onclick = function () {alert(name)}
</script>
</html>

效果如下所示:
在这里插入图片描述
觉得对你有帮助的话,点个赞再走吧!

http://www.yidumall.com/news/4144.html

相关文章:

  • 麦客网做网站营销推广怎么做
  • 烟台网站建设.com网站建设开发公司
  • 深圳营销型网站策划百度推广效果
  • 网站人工客服系统搜索引擎优化seo论文
  • 上海公司做网站怎么做互联网营销推广
  • 站群宝塔批量建站促销方法100种
  • 网站建设质量保证免费合作推广
  • 怎样做网站平台惠州百度seo在哪
  • 个人怎么做网站页面免费b2b网站推广
  • 牛牛襄阳做网站免费b站推广网站在线
  • ...东莞网站公司网站推广的途径有哪些
  • 网站做等保是什么意思湖南网站建设推广优化
  • 四川成都营销型网站新品牌推广方案
  • 商城网站建设费用太原seo网站排名
  • 前端做网站的兼职网站提交链接入口
  • 做花茶网站解说希爱力双效片用后感受
  • 做全国家电维修网站到哪里做视频剪辑培训
  • 宁波企业免费建站厦门人才网官网招聘
  • 桂林网站制作报价企业的互联网推广
  • 做二手车网站怎么做的营销案例100例简短
  • 成都网站设计哪家好爱战网关键词查询网站
  • 草桥网站建设公司百度竞价关键词
  • 只做恐怖片的网站创建自己的网站怎么弄
  • 免费做自己的网站有钱赚吗手机百度免费下载
  • 注册网站需要身份证吗市场调研公司排名
  • wordpress server酱石家庄百度快照优化排名
  • 怎么看网站关键词密度手机自己怎么建电影网站
  • 个人网站要在公安备案吗互联网营销方案策划
  • 高端科研网站设计全国疫情地区查询最新
  • 做设计的网站有哪些优秀网站设计欣赏