PHP 从另一个输入值减少值

我想从另一个输入值中获取输入值,

所以如果我在第一个输入中添加数字,

第二个输入从第一个输入中减少,

有人可以帮助我......


$value1 = 10;

echo "<input type='text' value='$value2'></input>";

$value3 = $value1 - $value2;

echo "<input type='text' value='$value3'></input>";


慕森王
浏览 99回答 2
2回答

繁华开满天机

使用 javascript 解决这类问题很容易处理<!DOCTYPE html><html><head>&nbsp; &nbsp; <title></title></head><body><input type="text" name="val2" id='val2' oninput="loadVal3(this.value)"><input type="text" name="val3" id='val3'><script type="text/javascript">&nbsp; &nbsp; function loadVal3(val) {&nbsp; &nbsp; &nbsp; &nbsp; let val1=10;&nbsp; &nbsp; &nbsp; &nbsp; if(!isNaN(val)&&val!=""){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('val3').value=val1-val;&nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('val3').value="";&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }</script></body></html>

慕桂英3389331

// i use the REQUEST&nbsp; HTTP Request variables (is can changed by GET Or Post request$secoundVarible = $_REQUEST['value'];$staticValue = 10;function reduceValue($num1,$num2){&nbsp; return $result = $num1 - $num2;&nbsp;}&nbsp;$reducedValue = reduceValue($staticValue, $secoundVarible);echo "<input type='text' value='$reducedValue'></input>";
打开App,查看更多内容
随时随地看视频慕课网APP