web前端开发-又双叒叕次数计算

用于计算又双叒叕次数,将带有又双叒叕语句转换

例如:我又双叒叕输了     转换成     我输了11次

闲得无聊写的这段代码,也算是提升个人的能力吧。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>计算器-qbr</title>
	<style>
		#an1,#an11{
			height: 60px;
			background-color: rgba(0, 0, 158, 0);
	        color:#000000;
	        border:0;
	        font-size: 16px;
	        box-sizing: content-box;				
            border-radius: 5px;
			margin: 0px;
		}
		#num{
			width: 421px;
			height: 80px;
			background-color: #ffffff;
			text-align: end;
			font-size: 20px;
			border: 0;
			border-radius: 10px;
		}
		#num1{
			width: 425px;
			height: 60px;
			background-color: #ffffff;
			text-align: end;
			font-size: 20px;
			border: 0;
			border-radius: 10px;
		}
		#an{
			width: 102.5px;
			height: 60px;
			background-color: #ffffff;
	        color:#000000;
	        border:0;
	        font-size: 16px;
	        box-sizing: content-box;				
            border-radius: 5px;
			margin-top: 5px;
		}
		#kuo1,#kuo2,#anq,#ans{
			width: 90px;
			height: 60px;
			background-color: #ffffff;
	        color:#000000;
	        border:0;
	        font-size: 16px;
	        box-sizing: content-box;				
            border-radius: 5px;
			margin-top: 5px;
		}
		#an2,#anf111{
			width: 102.5px;
			height: 102.5px;
			border: 0;
			background-color: #ffffff;
			border-radius: 10px;
			font-size: 20px;

		}
		#an3{
			width: 102.5px;
			height: 102.5px;
			border: 0;
			background-color: #abdfff;
			border-radius: 10px;
			font-size: 20px;
		}
		#anf{
			width: 102.5px;
			height: 102.5px;
			border: 0;
			background-color: #d4efff;
			border-radius: 10px;
			font-size: 20px;
		}
		#anf11{
			width: 102.5px;
			height: 102.5px;
			border: 0;
			background-color: #d4efff;
			border-radius: 10px;
			font-size: 20px;
		}
		#and1{
			width: 210px;
			height: 60px;
			border: 0;
			background-color: #abdfff;
			border-radius: 10px;
			font-size: 20px;
		}
		#anf1{
			width: 210px;
			height: 60px;
			border: 0;
			background-color: #d4efff;
			border-radius: 10px;
			font-size: 20px;
		}
	</style>
</head>
<body>
	<div style="background-color: #eeeeee;padding: 10px;width: min-content;border-radius: 15px;">
		<div>
			<script>
			function my(id){
				return document.getElementById(id);
			}

			</script>
		</div>
	
		<!-----生活计算器------>
		<div style="height: 20px;"></div>
		<div id="you">
			<input type="text" value=""placeholder="计算又双叒叕次数" id="num1"/>
			<div style="margin-top: 5px;">
				<input type="button" value="清除" id="anf1"/>
				<input type="button" value="计算" id="and1"/>
			</div>
			<script>
			function sleep(d){
				for(var t = Date.now();Date.now() - t <= d;);
			  }
			  
			my("and1").onclick=function(){
				var num11=my("num1").value;
				if(tongj(num11,"又")==0||tongj(num11,"双")==0||tongj(num11,"叒")==0||tongj(num11,"叕")==0){
					my("num1").value="没有包含又双叒叕字符";


				}else{
					var cis=tongj(num11,"又")+tongj(num11,"双")*2+tongj(num11,"叒")*3+tongj(num11,"叕")*4+1;
					var cis1=tongj(num11,"又")+tongj(num11,"双")+tongj(num11,"叒")+tongj(num11,"叕");
					num11=num11.replace("又","")
					num11=num11.replace("双","")
					num11=num11.replace("叒","")
					num11=num11.replace("叕","")
					var txt1=cis;
					txt1+="次"
					var txt=num11;
					txt+=txt1;
					my("num1").value=txt;
				}
				}
				//清除
				my("anf1").onclick=function(){
					my("num1").value=null;
				}
				//统计字符数量
			function tongj(str, a) {

				let b = str.indexOf(a);
				var num = 0;
				while (b !== -1) {
				console.log(b);
				num++;
				b = str.indexOf(a, b + 1)
				}
				return num;
			}
				//清除
			my("anq").onclick=function(){
				my("num1").value=null;
			}
			</script>
		</div>
	</div>
</body>
</html>

 效果图:

 

计算后结果:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值