<?php
$goods= isset($_POST['money']) ? $_POST['money'] : '苹果';
$price = isset($_POST['price']) ? $_POST['price'] : 0;
$count = isset($_POST['count']) ? $_POST['count'] : 1;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (is_numeric($count) && is_numeric($price)) {
$total = round($count*$price ,2) ;
echo '<script>alert("总计:'.$total.'元")</script>';
} else {
echo '<script>alert("请输入正确的金额~~")</script>';
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Apple</title>
<style>
.cont{
width: 500px;height: 350px;background: powderblue;margin: 10% auto;border-radius: 8px;
}
h3{width: 100%;line-height: 60px;text-align: center;
font-size: 26px;font-weight: 200;color: darkorchid;
}
input{width: 220px;height: 35px;border-radius: 8px;border: 1px solid #e8e8e8;outline:none;text-indent:1.2em;margin: 10px 10px 0px 15px}
span{float: left;margin-left: 30px;margin-right: 20px}
label{
float: left;margin-left: 30px;
}
select{
width: 220px;
height: 35px;
border-radius: 8px;
cursor: pointer;
padding-left: 20px;
outline: none;
}
</style>
</head>
<body>
<div class="cont">
<h3>Apple产品计算器</h3>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<p>
<span>产品型号:</span>
<select name="goods">
<option value="iphone6">iphone6</option>
<option value="iphone6 Plus">iphone6 Plus</option>
<option value="iphone7">iphone7</option>
<option value="iphone7 Plus">iphone7 Plus</option>
<option value="iphone8">iphone8</option>
<option value="iphone8 Plus">iphone8 Plus</option>
<option value="iphoneX">iphoneX</option>
</select>
</p>
<p><label>请输入单价:<input type="text" name="price">元</label></p>
<p><label>请输入数量:<input type="text" name="count">台</label></p>
<input type="submit" name="submit" value="计算" style="margin-left: 130px;margin-top: 30px;cursor: pointer">
</form>
</div>
</body>
</html>
/*
* is_numeric()判断文本框中是否输入的是数字
*&&是与的关系,从左到右,只要有一个不符合要求就不会执行
*/
***********************效果显示***********************************