求一段用php代码
求一段用php代码,网页上有个输入框,输入半径之后,点击按钮求圆的面积
------解决方案--------------------
<?php echo "<input type='text' id='round' value=''/>"; echo "<input type="button" id="submit" value="Submit" onclick="javascript:getArea()">"; echo "<p id="area"></p>"; ?> <script> var round; var area; var PI = 3.14; function getArea() { round = parseFloat(document.getElementById("round").value); area = 4/3*PI*round*round; setArea(area); } function setArea(area) { document.getElementById("area").innerHTML = "The Round's Area is : "+area ; } </script> <br><font color="#e78608">------解决方案--------------------</font><br>
$area = 0; if(isset($_GET['r'])) $area = pi()*$_GET['r']*$_GET['r']; echo 半径<input type="text" name="r"> <input type="submit" value="计算"> 面积=$area HTML; <div class="clear"> </div>