[英]echo a javascript variable
What is the best way to echo the variable get_parestotal? 回显变量get_parestotal的最佳方法是什么?
Some help please! 请帮忙! Thank you
谢谢
<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); ?>
You can log variables and so on in the console. 您可以在控制台中记录变量等。
eg: 例如:
console.log(get_parestotal);
You can even concatenate witht he use of + console.log('This is your variable'+get_parestotal) 您甚至可以使用+ console.log连接('这是您的变量'+ get_parestotal)
You can even add styling to your log (color, background-color,...): 您甚至可以在日志中添加样式(颜色,背景颜色......):
console.log('%cThis is your variable'+get_parestotal+'!','color:green;');
There are some alternatives to console.log() you could use: 您可以使用console.log()的一些替代方法:
console.warn();
console.info();
console.error();
console.debug();
You can either do alert(myvar) or console.log(myvar) . 您可以执行alert(myvar)或console.log(myvar) 。
Caveat: console.log is only supported in certain browsers...see the link. 警告:console.log仅在某些浏览器中受支持...请参阅链接。
如果你想要一个控制台输出而不是使用console.log(get_parestotal);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.