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>         
相关推荐
00后程序员张1 小时前
Fiddler抓包工具使用教程,代理设置与调试方法实战解析(含配置技巧)
前端·测试工具·ios·小程序·fiddler·uni-app·webview
2301_768350237 小时前
Vue第二期:组件及组件化和组件的生命周期
前端·javascript·vue.js
小周同学:7 小时前
Vue项目中将界面转换为PDF并导出的实现方案
javascript·vue.js·pdf
华洛8 小时前
公开一个AI产品的商业逻辑与设计方案——AI带来的涂色卡自由
前端·后端·产品
明远湖之鱼8 小时前
opentype.js 使用与文字渲染
前端·svg·字体
90后的晨仔9 小时前
Vue 3 组合式函数(Composables)全面解析:从原理到实战
前端·vue.js
今天头发还在吗9 小时前
【React】动态SVG连接线实现:图片与按钮的可视化映射
前端·javascript·react.js·typescript·前端框架
小刘不知道叫啥9 小时前
React 源码揭秘 | suspense 和 unwind流程
前端·javascript·react.js
szial9 小时前
为什么 React 推荐 “不可变更新”:深入理解 React 的核心设计理念
前端·react.js·前端框架
mapbar_front10 小时前
面试是一门学问
前端·面试