首頁 >php教程 >php手册 >简单的计算功能,简单计算功能

简单的计算功能,简单计算功能

WBOY
WBOY原創
2016-06-13 08:39:10921瀏覽

简单的计算功能,简单计算功能

效果图

要做出上面的效果图,我们需要对隐藏表单的元素有个简单的了解

隐藏表单的元素的语法格式为:,其功能是在浏览网页时使浏览器不显示这个表单字段元素,但在提交表单时将这个隐藏表单元素的name属性

和value属性值发送给服务器

<?<span>php
    </span><span>$CFQ</span> = <span>$_POST</span>["tag"];<span>//</span><span>判断用户是否单击了计算按钮</span>
    <span>if</span>(<span>$CFQ</span> == 1<span>)
    {
        </span><span>$addnum1</span> = <span>$_POST</span>["addnum1"];<span>//</span><span>通过$_POST内置数组获取加数</span>
        <span>$addnum2</span> = <span>$_POST</span>["addnum2"<span>];
    }
    </span><span>else</span><span>{
        </span><span>$addnum1</span> = <span>$addnum2</span> = 0<span>;        
    }
    </span><span>$sum</span> = <span>$addnum1</span> + <span>$addnum2</span><span>;
</span>?><span>
在表单中输入两个整数
</span><form name = "form1" method = "post" action = "#">
<input type = "hidden" name = "tag" size = "4" value="1"> <!--值用于做相等判断-->
<input type="text" name="addnum1" size="4" value="<?php echo <span>$addnum1</span>;?>">
+
<input type="text" name="addnum2" size="4" value="<?php echo <span>$addnum2</span>;?>">
=
<?php <span>echo</span> <span>$sum</span>;?><br>   <!--输出计算结果-->
<br><input type="submit" name="Submit" value="计算">
<input type="reset" name="Submit" value="重置">
</form>

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn