日期:2014-05-16  浏览次数:20312 次

关于JavaScript计算器的代码
function compute(obj)
{
obj.expr.value=eval(obj.expr.value);


为什么要加这个obj参数,这个事=号调用的函数

为什么要加一个<form>标记?

输入框<input> 那里的action是什么意思

最后一个问题就是为什么1.2*6不是显示7.2而是显示7.199999999999999

谢谢各位了

最后想认识一点熟悉JavaScript的朋友 愿意教我的麻烦留一下QQ 万分感激!


以下就是本人写的计算机的代码,问题的代码已经用红色字体标记
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<script type="application/javascript">

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 jia="+";

var jian="-";

var cheng="*";

var chu="/";

var point=".";

function enter(obj,string)

{

obj.expr.value+=string;

}

function clear(obj)

{

obj.expr.value="";

}

function tuige(obj)

{

   var tt=obj.expr.value;

   obj.expr.value=tt.substr(0,tt.length-1);

}


</script>

</head>



<body>

<form name="calc">

<table border="1" background="JavaScript/图片/20070703095251427.jpg" align="center">

<tr>

<td colspan="3"><input type="text" name="expr"  action="compute(this.form)" /></td>

<td>&nbsp;&nbsp;</td>

</tr>

<tr>

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

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

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

<td><input type="button" value="+" onclick="enter(this.form,jia)" /></td>

</tr>

<tr>

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

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

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

<td><input type="button" value="-" onclick="enter(this.form,jian)" /></td>

</tr>

<tr>

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

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

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

<td><input type="button" value="*" onclick="enter(thi