td><input type="text" name="second" size="12" /></td>
<td><input type="text" name="result" size="14" /></td></tr>
<tr><td colspan="3">运算类型:
<input type="button" value="+" onclick="calc('+')" />
<input type="button" value="-" onclick="calc('-')" />
<input type="button" value="*" onclick="calc('*')" />
<input type="button" value="/" onclick="calc('/')" />
</td></tr>
</table></form>
</body></html>
<form> 标签用于为用户输入创建 HTML 表单。
表单能够包含 input 元素,比如文本字段、复选框、单选框、提交按钮等等。
表单还可以包含 menus、textarea、fieldset、legend 和 label 元素。
表单用于向服务器传输数据。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>内置函数实现求和</title>
<script type="text/java script">
<!--
function sum()
{
var resultValue , firstValue ,secondValue; //声明3个变量,不给初值
firstValue = document.myform.first.value ;
secondValue = document.myform.second.value;
if(isNaN(firstValue))
{
alert(firstValue+"不是一个数字!");
return; /*注意,这里使用了return语句,表示程序走到这里就返//回了,下面的语句不被执行了。如果,思考下,去掉return,会怎样呢?*/
}
if(isNaN(secondValue))
{
alert(secondValue+"不是一个数字!");
return;
}
var num1=parseFloat(firstValue);
var num2=parseFloat(secondValue);
resultValue = num1 + num2 ;
document.myform.result.value = resultValue;
}
//-->
</script>
</head>
<body style="font-size:12px;">
<form name="myform">
加数:<input type="text" name="first" size=6>
被加数:<input type="text" name="second" size=6>
<input type="button" onclick="sum()" value="求和">
<input type="text" name="result" size=6>
</form>
</body>
</html>
if(counter == 10){
break;
}
等于号