<!DOCTYPE html>
<html>
<head>
	<title>简易计算器</title>
	<meta charset="utf-8">
	<style type="text/css">
		body {
			font-family: Arial, sans-serif;
			background-color: #f5f5f5;
		}
<pre><code>	h1 {
		text-align: center;
		margin-top: 50px;
	}

	form {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		align-items: center;
		margin-top: 30px;
	}

	input[type=&quot;number&quot;] {
		width: 150px;
		height: 40px;
		font-size: 20px;
		margin: 10px;
		padding: 5px;
		border: none;
		border-radius: 5px;
		background-color: #fff;
		box-shadow: 1px 1px 3px #ccc;
	}

	input[type=&quot;submit&quot;] {
		width: 100px;
		height: 40px;
		font-size: 20px;
		margin: 10px;
		padding: 5px;
		border: none;
		border-radius: 5px;
		background-color: #4CAF50;
		color: #fff;
		cursor: pointer;
	}

	input[type=&quot;reset&quot;] {
		width: 100px;
		height: 40px;
		font-size: 20px;
		margin: 10px;
		padding: 5px;
		border: none;
		border-radius: 5px;
		background-color: #f44336;
		color: #fff;
		cursor: pointer;
	}

	.result {
		font-size: 30px;
		font-weight: bold;
		text-align: center;
		margin-top: 30px;
	}
&lt;/style&gt;
</code></pre>
</head>
<body>
	<h1>简易计算器</h1>
	<form>
		<input type="number" name="num1" placeholder="请输入第一个数字" required>
		<select name="operator">
			<option value="+">+</option>
			<option value="-">-</option>
			<option value="*">*</option>
			<option value="/">/</option>
		</select>
		<input type="number" name="num2" placeholder="请输入第二个数字" required>
		<input type="submit" name="submit" value="计算">
		<input type="reset" name="reset" value="重置">
	</form>
	<div class="result">
		<?php 
			if(isset($_GET['submit'])) {
				$num1 = $_GET['num1'];
				$num2 = $_GET['num2'];
				$operator = $_GET['operator'];
				switch($operator) {
					case "+":
						echo $num1 + $num2;
						break;
					case "-":
						echo $num1 - $num2;
						break;
					case "*":
						echo $num1 * $num2;
						break;
					case "/":
						if($num2 != 0) {
							echo $num1 / $num2;
						} else {
							echo "除数不能为0";
						}
						break;
				}
			}
		?>
	</div>
</body>
</html>
使用HTML编写一个简易计算器界面使用表单控件完成界面设计要求具有计算功能。

原文地址: http://www.cveoy.top/t/topic/68I 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录