echo 一个 JavaScript 变量

gat*_*uso 5 javascript echo console-output

回显变量 get_parestotal 的最佳方法是什么?

请一些帮助!谢谢

  <script type="text/javascript">
 $(document).ready(function(){
                    var get_parestotal = 0
                $(".parestotal").each(function(){
                    get_parestotal += parseFloat($(this).text());
                });
                alert(get_parestotal);

            });

</script>



<? echo json_encode($get_parestotal); ?>
Run Code Online (Sandbox Code Playgroud)

mhx*_*mhx 7

您可以在控制台中记录变量等。

例如:

console.log(get_parestotal);
Run Code Online (Sandbox Code Playgroud)

您甚至可以使用+ console.log('This is your variable'+get_parestotal)连接

您甚至可以向日志添加样式(颜色、背景颜色...):

console.log('%cThis is your variable'+get_parestotal+'!','color:green;');
Run Code Online (Sandbox Code Playgroud)

您可以使用 console.log() 的一些替代方法:

 console.warn();
 console.info();
 console.error();
 console.debug();
Run Code Online (Sandbox Code Playgroud)