日期:2014-05-17  浏览次数:20525 次

求一段用php代码
求一段用php代码,网页上有个输入框,输入半径之后,点击按钮求圆的面积

------解决方案--------------------
PHP code
<?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>

------解决方案--------------------
PHP code
$area = 0;
if(isset($_GET['r'])) $area = pi()*$_GET['r']*$_GET['r'];
echo <<< HTML
<form>
半径<input type=text name=r>
<input type=submit value=计算>
</form>
面积=$area
HTML;