简体   繁体   English

有可能用JavaScript编写PHP逻辑?

[英]it is possible to write PHP logic in javascript?

Is it possible to write PHP logic in Javascript? 是否可以用Javascript编写PHP逻辑? I have this script but does not work well. 我有此脚本,但效果不佳。 Variable that appears always to the first criteria. 始终按照第一个条件出现的变量。

 <script>
    function subtotal(konversi){
        console.log('subtotal function');
        for(var j = 1; j < <?php echo"$cek";?>+1; j++){

            //First Criteria
            <?php if ($uom['uom_name'] =='KG') { ?> 
                var hitung = (document.getElementById('quantity'+j).value * document.getElementById('packing_value'+j).value);
            <?php } ?>

            //Second Criteria
            <?php if ($uom['uom_name'] =='MC') { ?> 
                var hitung = (document.getElementById('quantity'+j).value / document.getElementById('packing_value'+j).value);
             <?php } ?>

            document.getElementById('quantity_konversi'+j).value = hitung; 
            console.log(j, hitung);
        }
    } 
</script>

Please help me out and explain in detail because I am a newbie! 请帮助我,并详细解释,因为我是新手! Thanks 谢谢

PHP executes on the server and is completed before it hits the browser. PHP在服务器上执行,并在到达浏览器之前完成。 That's where JS comes in to play. 这就是JS发挥作用的地方。 There are techniques for the two to communicate (AJAX for example) but otherwise they serve different purposes. 两者之间存在通信的技术(例如AJAX),但它们的用途不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM