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

做网站有哪些主题免费制作自己的网页

做网站有哪些主题,免费制作自己的网页,长春app定制,上海网站建设浦东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.tj-hxxt.cn/news/97394.html

相关文章:

  • 望城区建设局网站网站流量分析的指标有哪些
  • 做网站卖什么小说百度搜索风云榜
  • 怎么建立一个表格seo优化一般多少钱
  • 做网站贵吗互联网推广引流
  • 丹阳如何做百度的网站成人短期就业培训班
  • 如何给英文网站做外链站长之家素材
  • 桓台做网站seo排名推广
  • 襄阳seo顾问衡阳seo外包
  • 医疗网站建站网站的推广方法有哪些
  • 网站制作用什么语言友情链接平台哪个好
  • 襄阳专业做网站郑州百度推广开户
  • 太原专业网站制作线上推广怎么做
  • 做网站平台成本seo排名优化方式方法
  • 免费企业网站源码大全关键词搜索方法
  • 网软志成学校网站管理系统官方商业正式版知名的搜索引擎优化
  • 网站建设费记什么科目2023年10月疫情恢复
  • 卡地亚手表官方网站seo优化方法
  • 山东建站管理系统知名品牌营销策划案例
  • 东莞清溪妇产科医院广州推广seo
  • 小草网络 网站建设百度竞价排名规则及费用
  • 东莞网络营销策划培训东莞seo计费
  • 做电路方案设计的网站杭州网站推广找哪家
  • 做海报找背景图有哪些网站网络营销的重要性
  • 做鞋子的网站北京做网站的公司排行
  • 网站系统找不到指定的文件百度竞价推广一个月多少钱
  • 重庆环保公司网站建设最近国际时事热点事件
  • 网站的按钮怎么做的百度指数平台官网
  • h5的制作步骤岳阳seo快速排名
  • 做网站小图标大全信息流优化师简历
  • 国内十大网站建设公司所有的竞价托管公司