`
- 浏览:
64439 次
- 性别:
- 来自:
杭州
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 22%;
margin: 20px 0 0 0;
}
table tr td{
text-align:center;
}
#Text1
{
width: 258px;
height: 38px;
}
.style2
{
width: 41px;
}
.Button
{
height: 35px;
width: 45px;
}
</style>
<script language="javascript" type="text/javascript">
var num;
function btntext(num) {
document.getElementById('Text1').value += document.getElementById(num).value;
}//文本框赋值
function ev() {
if (eval(document.getElementById('Text1').value!=null))
document.getElementById('Text1').value = eval(document.getElementById('Text1').value);
} //计算,文本框内的表达式
function clear1() {
document.getElementById('Text1').value =0;
} //将文本框内的内容清0
function SQRT() {
var disp = document.getElementById('Text1');
disp.value = Math.sqrt(disp.value);
}//开根号
function Pow() {
var disp = document.getElementById('Text1');
disp.value = Math.pow(disp.value, 2);
}//平方
function del() {
var disp = document.getElementById('Text1');
disp.value = disp.value.substring(0, disp.value.length - 1)
}//逐个删除
function C() {
var disp = document.getElementById('Text1');
disp.value = disp.value.substring(0, disp.value.length - disp.value.length)
}//清空
function keyDown(e) {
var realkey;
var keycode;
var show=false;
var Text1=document.getElementById("Text1");
var keycode=e.which || event.keyCode;
var txtvalue=Text1.value;
if(keycode<106&&keycode>95){
keycode=keycode-48;
}
if(keycode>47&&keycode<58){
realkey=String.fromCharCode(keycode);
show=true;
}else if(keycode==111){
realkey='/';
show=true;
}else if(keycode==106){
realkey='*';
show=true;
}else if(keycode==109){
realkey='-';
show=true;
}else if(keycode==107){
realkey='+';
show=true;
}else if(keycode==110){
realkey='.';
show=true;
}else if(keycode==13){
ev();
}else if(keycode==8){
Text1.value=Text1.value.substring(0,Text1.value.length-1);
}
if(show)
Text1.value=Text1.value+realkey;
}
document.onkeydown=keyDown
</script>
</head>
<body>
<div>
<table align="center" class="style1"
style="background-color: #C0C0C0; height: 330px;">
<tr>
<td colspan="4" style="background-color: #B0C4DE; text-align: center;">
<input id="Text1" type="text" onkeydown="if(event.keyCode==13) ev();"/></td>
</tr>
<tr>
<td style="background-color: #ADD8E6">
<input id="1" type="button" value="1" name='1' onclick="btntext('1')"class='Button' /></td>
<td style="background-color: #ADD8E6">
<input id="2" type="button" value="2" onclick="btntext('2')" class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="3" type="button" value="3" onclick="btntext('3')" class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="+" type="button" value="+" onclick="btntext('+')" class='Button'/></td>
</tr>
<tr>
<td style="background-color: #ADD8E6">
<input id="4" type="button" value="4" onclick="btntext('4')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="5" type="button" value="5" onclick="btntext('5')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="6" type="button" value="6" onclick="btntext('6')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="-" type="button" value="-" onclick="btntext('-')"class='Button'/></td>
</tr>
<tr>
<td style="background-color: #ADD8E6">
<input id="7" type="button" value="7" onclick="btntext('7')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="8" type="button" value="8" onclick="btntext('8')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="9" type="button" value="9" onclick="btntext('9')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="*" type="button" value="*" onclick="btntext('*')"class='Button'/></td>
</tr>
<tr>
<td style="background-color: #ADD8E6">
<input id="0" type="button" value="0" onclick="btntext('0')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="" type="button" value="←" onclick="del()" class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="." type="button" value="." style="font-weight: bold" onclick="btntext('.')"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="/" type="button" value="/" onclick="btntext('/')"class='Button'/></td>
</tr>
<tr>
<td style="background-color: #ADD8E6">
<input id='根号' type="button" value="√" onclick="SQRT()"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="平方" type="button" value="^2" onclick="Pow()"class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="" type="button" value="C" onclick="clear1()" class='Button'/></td>
<td style="background-color: #ADD8E6">
<input id="" type="button" value="=" onclick="ev()" class='Button'/></td>
</tr>
<td colspan="4"style="background-color: #B0C4DE" ><font size="2" color="#4682B4" ></font></td>
</tr>
</table>
</div>
</body>
</html>
[size=large][/size]
花了一天写,特别是键盘取值,开始迷茫死了~因为我是菜鸟~~~累死啦~不过成功了~~O(∩_∩)O哈哈~
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
本人编写的可以用键盘输入的C#简单计算器源码,屏蔽字母,只允许输入数字,欢迎各位指点错误,谢谢(并附带安装程序)!
用VC实现的支持键盘输入的简单计算器。希望对大家有用。
我学习JAVA时编的计算器小程序,完全支持键盘输入! 仅供学习交流用!
vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器编写vb计算器...
支持键盘输入的在线网页计算器,包含有防下载代码 用法:点一下淡黄色部分即可进行键盘输入运算
c#写的简单计算器,科学计算和普通运算,支持小键盘输入
一个简单的计算器,没什么功能 只能完成基本的计算
具备常用的加减乘除功能,界面前端置顶 不用频繁切换窗口 迷你界面 具有复制暂停功能 支持小键盘录入
Labview 计算器 全模拟Windows支持键盘输入
使用JS编写的计算器!可以执行加减乘除取余等操作,代码公开。
JAVA Script编写的计算器,界面较为简单,功能较少,可供初学者参考使用
参考博客:http://blog.csdn.net/xiaowei_cqu/article/details/7081348
输入数字: void CMyCalcDlg::PutIntoNum(int n) { CString Input; Input.Format("%d",n); //将Input以十进制格式化的形式输出,输出为n if (ResultData != "none" && OperatorName == "none") { Initialize...
一个好用的科学计算器……
纯javascript代码编写计算器程序.pdf
多功能计算器,有时项目中要,可直接使用。
花了半天写了一个VB的计算器,可以实现键盘输入
程序中主要运用堆栈这一数据逻辑结构。并建立了两个堆栈,当遇到 数字时直接压入操作数堆栈;当遇到加减乘除或左括号时进行优先级判断:如果传入的操作符优先级大于栈顶操作符的优先级则操作符入栈,如果传入的操作...
vb编写计算器,有源码,可供学习,!!!!!!
用JAVA编写计算器程序(模拟Windows计算器)