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>         
相关推荐
GISer_Jing2 分钟前
Todos
前端·人工智能·学习
hresh4 分钟前
两个 Chrome 窗口各 20 多个 tab 后,我把 tab-out 改成了更顺手的 TabNest
前端·chrome·后端
invicinble4 分钟前
前端技术栈--vuecli页面固定思路解密,与vue-router技术栈信息
前端·javascript·vue.js
shadowcz0078 分钟前
CHI 2026 归来:AI/LLM 正在重写人机交互的底层语法
前端·人工智能·html·人机交互
Moment11 分钟前
面试官:LangChain中 TS 和 Python 版本有什么差别,什么时候选TS ❓❓❓
前端·javascript·后端
JarvanMo15 分钟前
SINT能否取代GetX?
前端
Mintopia16 分钟前
深入理解计算机架构:从硬件到软件的桥梁
前端
大尚来也16 分钟前
HTTPS的性能优化:从握手延迟到会话复用
前端
尘埃落定wf18 分钟前
LangChain AgentExecutor 完全指南:ReAct循环+Memory+LLM实战
前端·javascript·react.js
数智前线19 分钟前
百灵大模型认领“Elephant”:Ling-2.6-flash定价每百万token 0.1美元
前端·javascript·microsoft