javascript - html内嵌PHP代码,点击checkbox更改php变量然后输出
滿天的星座
滿天的星座 2017-05-16 13:08:34
0
1
515
<?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>

这个只能更改Txt文本框的文本,不能实际改变php输出值
尝试过将将CheckBox放在表单提交 ,给 自己php判断,但是没有获取到
想请问下大家如何做这个谢谢哒

滿天的星座
滿天的星座

reply all(1)
给我你的怀抱

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!