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>         
相关推荐
2401_831943321 小时前
Element Plus对话框(ElDialog)全面指南:打造灵活弹窗交互
前端·vue.js·交互
计算机学姐1 小时前
基于SpringBoot的在线教育管理系统
java·vue.js·spring boot·后端·mysql·spring·mybatis
strongwyy1 小时前
DA14585墨水屏学习(2)
前端·javascript·学习
好青崧1 小时前
冒泡排序的原理
前端
椒盐螺丝钉1 小时前
CSS 基础知识分享:从入门到注意事项
前端·css
冬阳春晖2 小时前
web animation API 锋利的css动画控制器 (更新中)
前端·javascript·css
工业互联网专业3 小时前
基于springboot+vue的房屋租赁管理系统
java·vue.js·spring boot·毕业设计·源码·课程设计·房屋租赁管理系统
Python私教3 小时前
使用FastAPI和React以及MongoDB构建全栈Web应用05 FastAPI快速入门
前端·react.js·fastapi
浪裡遊3 小时前
Typescript中的对象类型
开发语言·前端·javascript·vue.js·typescript·ecmascript
杨-羊羊羊3 小时前
什么是深拷贝什么是浅拷贝,两者区别
开发语言·前端·javascript