如何将此程序转换为仅使用php而不使用JavaScript的计算?我使用echo“”;我应该用一个如果计算($选择)将Javascript转换为PHP
<html>
<head><title>hw4-5</title>
<style type='text/css'>
table{color:black;background-color:lightgray;border:6px solid black;border-width:4px;}
th{color:white;background-color:black;outline-style:solid;outline-width:2px;border:2px solid black;}
input.button{color:black;background-color:red;border:4px solid black;}
input#idname1,input#idname2,input#idname3{background-color:DEDEE6;border:4px solid black;}
</style>
<script type='text/javascript'>
function compute(choice)
{
var tbox1=document.getElementById('idname1');
var tbox2=document.getElementById('idname2');
var tbox3=document.getElementById('idname3');
if(choice==1){tbox2.value=parseInt(tbox1.value)*(tbox1.value);}
else if(choice==2){tbox3.value=parseInt(tbox1.value)*4;}
else if(choice==3){tbox2.value=parseInt(tbox1.value)*(tbox1.value);
tbox3.value=parseInt(tbox1.value)*4;}
else{tbox1.value=tbox2.value=tbox3.value='';}
}
</script>
</head>
<form>
<table>
<th colspan='2' >SQUARE PROBLEM</th>
<tr><td><label>Side: </label></td><td><input type='text' id='idname1' /></td></tr>
<tr><td><label>Area: </label></td><td><input type='text' id='idname2' /></td></tr>
<tr><td><label>Perimeter:</label></td><td><input type='text' id='idname3' /></td></tr>
<tr><td colspan='2' >
<input class='button' type='button' value='Area' onClick='compute(1)' />
<input class='button' type='button' value='Perimeter' onClick='compute(2)' />
<input class='button' type='button' value='Both' onClick='compute(3)' />
<input class='button' type='button' value='Clear' onClick='compute(4)' /></td></tr>
</table>
</form>
</html>
为什么不是ajax?计算将在php中完成,事件将由JS处理。额外的http请求这种情况将是矫枉过正,但嘿,这就是OP问 – 2013-03-06 06:16:24
@DamienPirsy这是真的,但是当OP甚至不想在那里的JavaScript,那么AJAX是没有问题,我假设。由于OP说'只有PHP的计算在那里,而不使用JavaScript' – 2013-03-06 06:20:10