Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以将 js var 等同于 php var?
<?php $count=0; ?> <?php $count++; ?>
...
<script>var $total = {<?php $count; ?>};</script>
像这样的东西
<script> var total = 5; var total2 = <?= $count ?>; if( total == total2 ) { // IT works! } </script>
请记住,此处的 PHP 是在页面到达浏览器之前呈现的(将在其中执行 javascript)。
编辑:另请注意,在您发布的示例中,使用 {} 将导致 javascript 将元素视为对象而不是原始整数,这似乎是您的目标。