网页计算器 html代码原理,HTML网页之计算器代码

本文介绍了一个简单的HTML网页计算器的实现,通过JavaScript进行数值运算。用户可以点击数字和运算符进行计算,同时提供了清零和求结果的功能。代码中使用了eval函数来计算表达式的值,并实时更新显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

计算器网页效果显示:点击这里!

2dbdb2bf4b1d72198a0fb395dc5868d6.png

function show(){

var date = new Date(); //日期对象

var now = "";

now = date.getFullYear()+"年"; //读英文即可了

now = now + (date.getMonth()+1)+"月"; //取月的时候取的是当前月-1假设想取当前月+1就能够了

now = now + date.getDate()+"日";

now = now + date.getHours()+"时";

now = now + date.getMinutes()+"分";

now = now + date.getSeconds()+"秒";

document.getElementById("nowDiv").innerHTML = now; //div的html是now这个字符串

setTimeout("show()",1000); //设置过1000毫秒就是1秒,调用show方法

}

Calculator

var numresult;

var str;

function onclicknum(nums) {

str = document.getElementById("nummessege");

str.value = str.value + nums;

}

function onclickclear() {

str = document.getElementById("nummessege");

str.value = "";

}

function onclickresult() {

str = document.getElementById("nummessege");

numresult = eval(str.value);

str.value = numresult;

}

img{

position:absolute;

left:1100px;

top:100px;

}

主页面

网络人VS灰鸽子工作室

style="height: 350px; 270px">

style="height: 90px; 350px; font-size: 50px" />

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

style="height: 70px; 190px; font-size: 35px">

style="height: 70px; 90px; font-size: 35px">

οnclick="onclicknum('/')"

style="height: 70px; 90px; font-size: 35px">

οnclick="onclickclear()"

style="height: 70px; 190px; font-size: 35px" />

οnclick="onclickresult()"

style="height: 70px; 190px; font-size: 35px" />

Design by:

>网络人VS灰鸽子

2016-3-3                                           邮箱:linux_drv@yeah.net
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值