草根站长是一个网站架设的学习平台,提供最新的网站制作与网站运营等教程
网站map 会员中心 论坛
当前位置: 主页 > 网页特效 > 综合脚本特效 >

普通的计算器,只有加减乘除运算,支持小数点

来源:网络整理更新时间:2012-08-26 16:18点击:
运行代码 源代码调试

    [ 可先修改部分代码 再运行查看效果 ]

当前位置:惠州网站制作|惠州网页设计|惠州模版制作|惠州模版仿制|网站达人 → 文章中心 → 网页特效 普通的计算器,只有加减乘除运算,支持小数点-综合脚本特效 作者:佚名  来源:本站整理  发布时间:2009-05-31 01:12:54

<!-- 把如下代码加入<body>区域中 -->

<script language="JavaScript">

<!-- Hide the script from old browsers --

function compute(obj)

   {obj.expr.value = eval(obj.expr.value)}

var one = '1'

var two = '2'

var three = '3'

var four = '4'

var five = '5'

var six = '6'

var seven = '7'

var eight = '8'

var nine = '9'

var zero = '0'

var plus = '+'

var minus = '-'

var multiply = '*'

var divide = '/'

var decimal = '.'

function enter(obj, string)

   {obj.expr.value += string}

function clear(obj)

   {obj.expr.value = ''}

// --End Hiding Here -->

</script>

<form name="calc">

<table border=1>

<td colspan=4><input type="text" name="expr" size=30 action="compute(this.form)"> <tr>

<td><input type="button" value="  7  " onClick="enter(this.form, seven)">

<td><input type="button" value="  8  " onClick="enter(this.form, eight)">

<td><input type="button" value="  9  " onClick="enter(this.form, nine)">

<td><input type="button" value="   /  " onClick="enter(this.form, divide)">

<tr><td><input type="button" value="  4  " onClick="enter(this.form, four)">

<td><input type="button" value="  5  " onClick="enter(this.form, five)">

<td><input type="button" value="  6  " onClick="enter(this.form, six)">

<td><input type="button" value="  *  " onClick="enter(this.form, multiply)">

<tr><td><input type="button" value="  1  " onClick="enter(this.form, one)">

<td><input type="button" value="  2  " onClick="enter(this.form, two)">

<td><input type="button" value="  3  " onClick="enter(this.form, three)">

<td><input type="button" value="   -  " onClick="enter(this.form, minus)">

<tr><td colspan=2><input type="button" value="       0       " onClick="enter(this.form, zero)">

<td><input type="button" value="   .  " onClick="enter(this.form, decimal)">

<td><input type="button" value="  +  " onClick="enter(this.form, plus)">

<tr><td colspan=2><input type="button" value="   =   " onClick="compute(this.form)">

<td colspan=2><input type="button" value="AC" size= 3 onClick="clear(this.form)"> </table>

</form>

上一篇文章:水中倒影的时间特效代码-时间日期特效 下一篇文章:大学生创业:魔术网站和淘宝店月收入过万

相关特效:

推荐特效