<?php
echo "<img src=\"http://ithelp.ithome.com.tw/upload/images/20170630/20106116KJ629DZAgt.png\">";
//詳細的
?>
超簡單
交流一下,用JS的版本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
input {
font-size: 18px;
color: #666
}
button {
font-size: 20px;
width: 25px;
text-align: center
}
#result {
display: inline-block;
width: 100px;
border: 1px dashed #666;
padding: 5px;
font-size: 20px;
text-align: center
}
</style>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
</head>
<body>
<input type="text" id="n1" size="10" value="0" />
<input type="text" id="n2" size="10" value="0" />
<button id="plus">+</button>
<button id="minus">-</button>
<button id="times">X</button>
<button id="divid">/</button>
<span id="result">Result</span>
<script>
$(function() {
var collectNum = function() {
return [Number($("#n1").val()), Number($("#n2").val())];
}
var showNum = function(result) {
$("#result").html(result);
}
$("button").click(function() {
var nums = collectNum();
switch ($(this).attr("id")) {
case "plus":
showNum(nums[0] + nums[1]);
break;
case "minus":
showNum(nums[0] - nums[1]);
break;
case "times":
showNum(nums[0] * nums[1]);
break;
case "divid":
showNum(nums[0] / nums[1]);
break;
}
});
});
</script>
</body>
</html>
SUBMIT 也可以傳值的
<?php
$num1=$_POST['num1'];
$num2=$_POST['num2'];
if($_POST['a']=='+')
{ $total=$num1+$num2;}
if($_POST['a']=='-')
{ $total=$num1-$num2;}
if($_POST['a']=='*')
{ $total=$num1*$num2;}
if($_POST['a']=='/')
{ $total=$num1/$num2;}
?>
<form action="test888.php" method="post" name="form">
<table width="30%" border="0">
<tr>
<td rowspan="4"><input name="num1" type="text" size="5" value="<?php echo $num1;?>"/> <input name="num2" type="text" size="5" value="<?php echo $num2;?>"/></td>
<td><input name="a" type="submit" value="+" onclick=""/></td>
<td rowspan="4"><input name="resullt" type="text" value="<?php if($total=="" && $total!="0"){echo "Result";}else{echo $total;}?>" readonly="readonly" /></td>
</tr>
<tr>
<td>
<input name="a" type="submit" value="-" onclick=""/>
</td>
</tr>
<tr>
<td>
<input name="a" type="submit" value="*" onclick=""/>
</td>
</tr>
<tr>
<td>
<input name="a" type="submit" value="/" onclick=""/>
</td>
</tr>
</table>
</form>