简单网页计算器代码大全_用web制作简单计算器

简单网页计算器代码大全_用web制作简单计算器注:本人为初学者,欢迎各位大神指教简单计算器实现效果:HTML代码counter.html计算器

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

注:本人为初学者,欢迎各位大神指教
在线试一试
简单计算器实现效果:
这里写图片描述
HTML代码counter.html

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>计算器</title>
		<link rel="stylesheet" type="text/css" href="css/counter.css" />
		<script type="text/javascript" src="js/counter.js"></script>
	</head>

	<body>
		<div class="counter">
			<div class="counter_top" >
				<form>
					<input type="text" id="top" value="" />
				</form>
			</div>
			<div class="counter_down">

				<form>
					<input type="button" class="CE" value="清屏" onclick="cl(this.value)" />
					<input type="button" class="CE" value="退格" onclick="cl(this.value)"/>
					<div class="down_right" id="cou">
						<input type="button" class="cou" value="÷" onclick="eva(this.value)"/>
						<input type="button" class="cou" value="×" onclick="eva(this.value)"/>
						<input type="button" class="cou" value="-" onclick="eva(this.value)"/>
						<input type="button" class="cou" value="+" onclick="eva(this.value)"/>
						<input type="button" class="cou" value="=" onclick="eva(this.value)"/>
					</div>
					<div id="down_num" >
						<input type="button" class="num" value="7" onclick="show(this.value)"/>
						<input type="button" class="num" value="8" onclick="show(this.value)"/>
						<input type="button" class="num" value="9" onclick="show(this.value)"/>
						<input type="button" class="num" value="4" onclick="show(this.value)" />
						<input type="button" class="num" value="5" onclick="show(this.value)" />
						<input type="button" class="num" value="6" onclick="show(this.value)"/>
						<input type="button" class="num" value="1" onclick="show(this.value)"/>
						<input type="button" class="num" value="2" onclick="show(this.value)"/>
						<input type="button" class="num" value="3" onclick="show(this.value)"/>
						<input type="button" class="num" value="0" onclick="show(this.value)"/>
						<input type="button" class="num" value="." onclick="show(this.value)"/>
						<input type="button" class="num" value="+/-" onclick="eva(this.value)"/>
					</div>

				</form>

			</div>
		</div>
	</body>

</html>

CSS代码counter.css

.counter{
	background-color: #E0E0E0;
	width: 440px;
	height: 460px;
	padding: 20px;
}

.counter .counter_top{
	width: 440px;
	height: 53px;
	background-color: #fff;
}

.counter .counter_top input{
	width: 440px;
	height: 53px;
	border: 0px;
}

.counter_down .CE{
	width: 152.5px;
	height: 45px;
	margin: 15px 15px 0px 0px;
}

.counter_down .cou{
	width: 95px;
	height: 45px;
	margin-bottom: 15px;
}

.down_right{
	width: 95px;
	float: right;
	margin-top: 15px;
}

.counter_down .num{
	width: 95px;
	height: 45px;
	margin: 15px 16px 0px 0px;
}

js代码counter.js


var a=0;
var b;
var c = 0;

function show(value) {	
	document.getElementById("top").value +=value;		
}

function eva(value){
	c=parseFloat(document.getElementById("top").value);
	
	if (value=="=") {
		if(b=="+"){
			document.getElementById("top").value=(a+c);
		}else if(b=="-"){
			document.getElementById("top").value=(a-c);
		}else if(b=="×"){
			document.getElementById("top").value=(a*c);
		}else if(b=="÷"){
			if(c==0){
				document.getElementById("top").value="分母不能为0";
			}else{
				document.getElementById("top").value=(a/c);
			}	
		}
	}else{
		a=parseFloat(document.getElementById("top").value);
		document.getElementById("top").value="";
		b=value;
		if(b=="+/-"){
			a=-a;
			document.getElementById("top").value=a;
		}
	}	
}

function cl(value){
	if(value=="清屏"){
		document.getElementById("top").value="";
	}else{		document.getElementById("top").value=document.getElementById("top").value.substring(0,(document.getElementById("top").value.length-1))
	}	
}


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182540.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python安装的库在pycharm不显示_pycharm上无法安装各种库

    python安装的库在pycharm不显示_pycharm上无法安装各种库在使用pycharm安装库总是出现安装不成功的提示‘Non-zeroexitcode(2)’错误提示:最后找了很多方法都不能安装成功,最后发现可以降级pip就可以步骤:1、点击Terminal2、在里面输入“python-mpipinstallpip==20.2.4”对pip进行降级3、重新安装你需要的库或者模块…

    2022年8月26日
    4
  • .NET中pdb文件的作用是什么「建议收藏」

    .NET中pdb文件的作用是什么「建议收藏」.PDB是ProgramDatabase的缩写,全称为“程序数据库”文件。我们使用它(更确切的说是看到它被应用)大多数场景是调试应用程序。目前我们对.PDB文件的普遍认知是它存储了被编译文件的调试信息,作为符号文件存在。 PDB文件寻路 如果我们观察VS启动调试加载模块和符号文件的过程,会发现它通常会从可执行文件或者DLL文件的相同目录中加载符号文件。这正是调试器寻找PDB文件的

    2022年5月5日
    116
  • ntp时间同步协议_ntp服务器搭建

    ntp时间同步协议_ntp服务器搭建一、简介1.作用NTP是从时间协议(TimeProtocol)和ICMP时间戳报文(ICMPTimeStampMessage)演变而来,在准确性和健壮性方面进行了特殊的设计,理论上精度可达十亿分之一秒。NTP协议应用于分布式时间服务器和客户端之间,实现客户端和服务器的时间同步,从而使网络内所有设备的时钟基本保持一致。NTP协议是基于UDP进行传输的,使用端口号为123。2.特征NTP提供了准…

    2022年10月11日
    0
  • linux创建文件命令vim_vim文件

    linux创建文件命令vim_vim文件创建文件【vi】一、进入vi的命令vifilename:打开或新建文件,并将光标置于第一行首vi+nfilename:打开文件,并将光标置于第n行首vi+filename:打开文件,并将光标置于最后一行首vi+/patternfilename:打开文件,并将光标置于第一个与pattern匹配的串处vi-rfilename:在上次正用vi编辑时发生系统崩溃,恢复filena…

    2025年12月3日
    2
  • ubuntu安装cuda和cudnn_ubuntu查看是否安装cuda

    ubuntu安装cuda和cudnn_ubuntu查看是否安装cuda目录1、查看系统推荐的cuda版本2、官网下载cuda软件包3、安装4、环境配置5、验证cuda是否正常1、查看系统推荐的cuda版本查看前应先安装显卡驱动,可以查看NVIDIA显卡驱动安装nvidia-smi这里显示的是cuda11.4版本2、官网下载cuda软件包官网cuda下载对应的cuda版本这里选择11.4.4的版本wgethttps://developer.download.nvidia.com/comput.

    2022年9月23日
    3
  • STM32-USART串口通信【USART和UART的区别】[通俗易懂]

    STM32-USART串口通信【USART和UART的区别】[通俗易懂]介绍了USART和UART的区别、STM32的USART1的寄存器和配置方法以及常见的问题,适合速查!

    2022年5月19日
    47

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号