圆周长面积的计算,一个下拉列表框,用于选择计算圆的周长或者是面积,一个点击按钮进行计算。
也就是函数的调用
DOCTYPE html>
<html lang&#61;"en"><head><meta charset&#61;"UTF-8"><meta http-equiv&#61;"X-UA-Compatible" content&#61;"IE&#61;edge"><meta name&#61;"viewport" content&#61;"width&#61;device-width, initial-scale&#61;1.0"><title>对象title>
head><body>请输入圆的半径&#xff1a;<input type&#61;"text" name&#61;"radius" id&#61;"radius"><select name&#61;"type" id&#61;"type"><option value&#61;"circle">周长option><option value&#61;"area">面积option><option value&#61;"volume">体积option>select><input type&#61;"button" value&#61;"计算" id&#61;"btnCal"><script>function getCircle(r) {return 2 * Math.PI * Math.pow(r, 2);}function getArea(r) {return Math.PI * 2*r;}function getVolume(r) {return (4 / 3) * Math.PI * Math.pow(r, 2);}var x &#61; document.getElementById("btnCal");x.onclick &#61; function () {var r &#61; parseFloat(document.getElementById("radius").value);var type &#61; document.getElementById("type").value;var result;switch (type) {case &#39;circle&#39;: result &#61; getCircle(r); break;case &#39;area&#39;: result &#61; getArea(r); break;case &#39;volume&#39;: result &#61; getVolume(r); break;default: result &#61; 0;}alert("计算结果为" &#43; result.toFixed(2));} script>
body>html>