编写函数,实现求圆面积
从页面输入圆半径,在控制台中打印出圆面积。
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>圆面积</title>
</head>
<body>
<script>
function ab() {
var r = document.getElementById("a").value;
var area = parseInt(3.14 * r * r);
alert("半径为" + r + "的圆面积为:" + area);
}
</script>
半径<input type="text" id="a">
<button onclick="ab()">提交</button>
</body>
</html>