switch按钮文字切换

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
	<style>
		body{background: rgb(57, 179, 255)}
		label {
			display: block;
			width: 70px;
            height: 30px;
		}
		.mui-switch + .mui-switch-text {
			width: 100%;
			height: 100%;
			border: 1px solid #fff;
            background-color: transparent;
			display: flex;
			align-items: center;
			position: relative;
		}
		.mui-switch-text:before {
            content: '译';
            width: 50%;
            height: 100%;
			top: 0;
            left: 0;
            position: absolute;
			display: flex;
			align-items: center;
			justify-content: center;
			color: rgb(57, 179, 255);
			transition: left 0.2s;
            background-color: #fff; }
		.mui-switch:checked + .mui-switch-text:before {
			content: '英';
            left: 50%; }
		.mui-switch + .mui-switch-text span {
			display: inline-block;
			width: 50%;
			text-align: center;
			color: #fff;
		}
	</style>
</head>
<body>
	<label>
		<input class="mui-switch" onclick="switchs(this)" type="checkbox" hidden>
		<div class="mui-switch-text"><span>译</span><span>英</span></div>
	</label>
	<div class="text">false</div>
	<script>
	function switchs(dom){
		document.querySelector('.text').innerText = dom.checked;		
	}
	</script>
</body>
</html>

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值