javascript 计算圆的面积 无法成功运行
<head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title>计算圆面积</...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>计算圆面积</title>
<script type="text/jscript">
function ArtRound(){
var rid = parseFloat(document.getElementById("txtArt").value);
var area = match.PI * rid*rid;
document.getElementById("txtRound").setAttribute("value",area);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<p>圆半径为:</p>
<input typt="text" id="txtArt" name="txtAtr" /><br>
<p> 圆面积为:</p>
<input typt="text" id="txtRound" name="txtRound" /><br>
<input type="submit" name="button" id="button" value="计算面积" onclick="ArtRound()" />
<br>
</form>
</body> 展开
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>计算圆面积</title>
<script type="text/jscript">
function ArtRound(){
var rid = parseFloat(document.getElementById("txtArt").value);
var area = match.PI * rid*rid;
document.getElementById("txtRound").setAttribute("value",area);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<p>圆半径为:</p>
<input typt="text" id="txtArt" name="txtAtr" /><br>
<p> 圆面积为:</p>
<input typt="text" id="txtRound" name="txtRound" /><br>
<input type="submit" name="button" id="button" value="计算面积" onclick="ArtRound()" />
<br>
</form>
</body> 展开
3个回答
2013-01-18 · 知道合伙人互联网行家
关注
展开全部
其中有2点小问题:
1.js中数学对象Math要大写首字母。Math.PI
2.submit类型的input在被点击后出发submit()事件,一点击表单就被提交,可在onclick里使用“ return false;”屏蔽。
修改后的HTMl如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
计算圆 面积
</title>
<script type="text/jscript">
function ArtRound() {
var rid = parseFloat(document.getElementById("txtArt").value);
var area = Math.PI * rid * rid;
document.getElementById("txtRound").setAttribute("value", area);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<p>
圆半径为:
</p>
<input typt="text" id="txtArt" name="txtAtr" />
<br>
<p>
圆面积为:
</p>
<input typt="text" id="txtRound" name="txtRound" />
<br>
<input type="submit" name="button" id="button" value="计算面积"
onclick="ArtRound();return false;"/>
<br>
</form>
</body>
</html>
1.js中数学对象Math要大写首字母。Math.PI
2.submit类型的input在被点击后出发submit()事件,一点击表单就被提交,可在onclick里使用“ return false;”屏蔽。
修改后的HTMl如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
计算圆 面积
</title>
<script type="text/jscript">
function ArtRound() {
var rid = parseFloat(document.getElementById("txtArt").value);
var area = Math.PI * rid * rid;
document.getElementById("txtRound").setAttribute("value", area);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<p>
圆半径为:
</p>
<input typt="text" id="txtArt" name="txtAtr" />
<br>
<p>
圆面积为:
</p>
<input typt="text" id="txtRound" name="txtRound" />
<br>
<input type="submit" name="button" id="button" value="计算面积"
onclick="ArtRound();return false;"/>
<br>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询