HTML 实现 点击按钮切换 整张界面 && 点击按钮切换局部界面

点击按钮实现页面切换

点击按钮切换全局界面

方法一: 使用a标签进行跳转连接 href

python 复制代码
 <a href="/index_secret">
     <button class="change_page">利率计算器</button>
 </a>

注意一下所出现的herf 连接都可以是直接的网站以及本地直接写的html页面的路径

方法二:在button标签中加上onclick属性,赋值为Javascript

python 复制代码
<input type="button" onclick='location.href=("index.aspx")' />//在本页面打开
<input type="button" onclick='window.open("bedzhao.aspx")' />//打开新页面

<button onclick="window.location.href='../routeEdit/index.html'" type="button" id="add">新增</button>

方法三:触发一个函数跳转

python 复制代码
<script>
function jump(){
    window.location.href="http://blog.sina.com.cn/mleavs";
}
</script>
<input type="button" value="我是一个按钮" οnclick=javascript:jump()>

方法四:表单的action定向提交跳转

python 复制代码
<form action="xx.html" method="post">
    <input type="button" value="按钮">
</form>

点击按钮切换局部界面

方法一:用模块的style.display状态

我们利用button的value的值变化进行编写函数,每次点击对应一个事件,在这个事件里我们进行判断 ,如果button.value是其中一个我就将这个标签的style设置为none("显示") /block("不显示")

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>test</title>
	</head>
	<body>
	<input type="button" value="隐藏" onclick="show()" id="btn1">
	<div id="div1" style="width: 200px; height: 200px; background-color: rgb(255, 136, 0);">
		
	</div>
	</body>
<script type="text/javascript">
		function show(){
			var btnobj=document.getElementById("btn1");
			var divobj=document.getElementById("div1");
			if(btnobj.value=="隐藏"){
				divobj.style.display="none";
				btnobj.value="显示";
			}else{
				divobj.style.display="block";
				btnobj.value="隐藏";
			}
		}
	

	</script>
</html>

方法二:Vue框架

html 复制代码
<html>
	<head>
        <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
	</head>
	<body>
        <div id="app1">
            <input type="button" @click="flag = !flag" :value='able()'>
            <div id="div1" style="width: 200px; height: 200px; background-color: rgb(255, 136, 0);" v-show="flag"></div>
        </div>
	</body>
    <script>
        var app = new Vue({
        el: '#app1',
        data: {
            flag: true,
        },
        methods:{
            able(){
                if (this.flag){
                    return '隐藏'
                }else{
                    return '显示'
                }
            }
        }
        })
    </script>
</html>         
相关推荐
程序员海军15 小时前
用了两年多 GPT,我最近开始换模型了,还折腾了个求职避坑 Agent
前端·人工智能·后端
zttbee16 小时前
echarts图表tooltip色块失效
前端·javascript·echarts
excel17 小时前
IndexNow:让搜索引擎更快发现网站更新的主动通知协议
前端·后端·架构
子兮曰17 小时前
CSS 复现 23 种设计风格:从拟物到液态玻璃的成本阶梯与兜底写法【实战】
前端·css·视觉设计
虚无境18 小时前
如何用AI帮我写出实用的插件
前端·javascript·ai编程
柳杉19 小时前
从数字化到数智化:3D 可视化大屏的下一个五年
前端·ai编程·数据可视化
濮水大叔19 小时前
函数式与对象式:前端架构的两种成本曲线
vue.js·react.js·函数式编程
风骏时光牛马19 小时前
从零到实战:AI全栈学习进阶路线
前端
FRing0320 小时前
JavaScript入门到精通二十六(变量提升、函数剩余参数、展开运算符、ES6箭头函数)
开发语言·前端·javascript·es6·箭头函数
用户3600555790020 小时前
Kestrel_VLLM - 15 · decode 优化四连击:19ms → 8ms
前端