<?php
$coin=1280;
$money=1121;
$coinsale=$coin/100;
?>
<input id="money" type="hidden" value="<?php echo $money?>">
<input id="coin" type="checkbox" value="<?php echo $coinsale?>" onclick="checkboxOnclick(this)">asdsa<br>
<input id="salemoney" type="txt" style="border: none" readonly="true" ><?php echo $money?>
</body>
<script type="text/javascript">
function checkboxOnclick(checkbox) {
var num1=document.getElementById("money").value;
var num2=document.getElementById("coin").value;
var num3=num1-num2;
if (checkbox.checked == true){
document.getElementById("salemoney").value=num3;
}else{
document.getElementById("salemoney").value=num1;
}
}
</script>
This can only change the text of the Txt text box, but cannot actually change the PHP output value
I tried putting the CheckBox in the form submission and gave my own PHP judgment, but I didn't get it
I would like to ask you how to do it Thank you for this
给我你的怀抱2017-05-16 13:10:34
Just write an ajax interface in the background.
ajax I won’t write it, if you don’t know how to Google it yourself.
public function returnSaleMoney(){
$num1 = $_POST[''];
$num2 = $_POST[''];
$res = '自己写计算方法';
echo json_encode($res);
}
Personally, if you want to change the output value here, it is more appropriate to use js to handle it.