我想将值从 php 传递到 js 文件,像这样的代码但不工作有什么问题吗?
谢谢
php 文件
$var = 10;
<script>
var phpVar = "<?php echo json_encode($var) ?>;";
</script>
<script type="text/javascript" src='vendor/circliful/circliful.custom.js'></script>
js 文件
$("#overallProgress").circliful({
animationStep: 5,
foregroundBorderWidth: 12,
backgroundBorderWidth: 6,
percent: 'alert(phpVar);', **<-- place value from php**
fontColor: '#000000',
foregroundColor: '#1a8e5f',
backgroundColor: 'rgba(0, 0, 0, 0.1)',
// icon: '\eab4',
iconColor: '#1a8e5f',
iconPosition: 'middle',
// text: 'Statistik',
textBelow: true,
animation: 1,
animationStep: 1,
start: 2,
showPercent: 1,
});
抱歉,我在 php 中有错误代码,这是正确的代码
<?php
$var = 67;
?>
<script>
var phpVar = <?php echo json_encode($var) ?>;
</script>
<script type="text/javascript" src='vendor/circliful/circliful.custom.js'></script>
繁花如伊