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

做网站有哪些主题数据统计网站

做网站有哪些主题,数据统计网站,武汉做网站公司电话,java 做直播网站有哪些软件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.wangmingla.cn/news/82289.html

相关文章:

  • 网站开发思维导图推广计划书怎么写
  • 揭阳市建设发展总公司网站哈尔滨优化网站公司
  • 局域网建设网站如何访问优化设计六年级下册数学答案
  • 彩票网站开发制作平台软件百度官网app
  • 班级手机网站墨刀怎样做免费建站软件
  • 哪个网站能买到做披萨的芝士正宗各大网站收录入口
  • 做亚马逊有哪些站外折扣网站广州网络优化最早的公司
  • 企业网站建设定制开发服务东莞建设企业网站
  • 临沂罗庄建设局网站电子商务网站建设多少钱
  • zencart 网站安装sem优化托管公司
  • 卡片式网站湖南有实力seo优化哪家好
  • 国外优秀企业网站欣赏会计培训班推荐
  • 建站之星快速建站价格百度推广需要多少钱
  • 学做美食视频在哪个网站搜索引擎有哪几个网站
  • 适合宝妈做兼职的网站百度权重10的网站
  • 做视频网站赚钱seo推广软件排行榜
  • 十大网购平台排行榜重庆seo代理计费
  • 疯狗做网站网站推广的方法有哪些?
  • 做欧洲电商看哪个网站生意参谋指数在线转换
  • 兰州app外包太原seo快速排名怎么样
  • asp做新闻网站seo外包公司需要什么
  • 软件下载类型网站怎么做优秀网页设计作品
  • 3g网站app网络营销的优势
  • 网站建设活动广告南宁网站建设公司
  • seo外链网站大全手机优化软件排名
  • WordPress商务网站网址收录
  • 企业网站建设单位网络营销模式有哪几种
  • 云南网站开发公司网站搜索引擎优化的基本内容
  • 法治建设的网站搜索网排名
  • 苏州 网站制作公司怎么打开网站