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

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

WBOY
Release: 2016-06-13 08:39:10
Original
923 people have browsed it

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

效果图

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

隐藏表单的元素的语法格式为:,其功能是在浏览网页时使浏览器不显示这个表单字段元素,但在提交表单时将这个隐藏表单元素的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>
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template