2

如何在 jquery 中获取 php echo 数据。我想要 jquery 中的 dataDAY1。我在进度条上使用。我使用 php 和 sql。我从数据库中获取了总 var total_goals 和 var targets_completed 数据

<div id="dataDAY1"><?php echo $row["ipoSize"]; ?></div>

<script>
    $(document).ready(function(){
        var total_goals = document.getElementById("dataDAY1")
        // var total_goals = '$json_array';
        var goals_completed = 3000;

        var bar = new ProgressBar.Circle('#container', {
            color: '#00b819',
            strokeWidth: 4,
            trailWidth: 4,
            easing: 'easeInOut',
            duration: 1400,
            text: {
                autoStyleContainer: false
            },
            from: { color: '#cecece', width: 4 },
            to: { color: '#00b819', width: 4 },
            step: function(state, circle) {
                circle.path.setAttribute('stroke', state.color);
                circle.path.setAttribute('stroke-width', state.width);

                var value = Math.round(circle.value() * 100);
                if (value === 0) {
                    circle.setText('');
                } else {
                    circle.setText(value);
                }
            }
        });
        bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif';
        bar.text.style.fontSize = '2rem';
        bar.animate(goals_completed/total_goals);  // Number from 0.0 to 1.0
    });
</script>
4

3 回答 3

1

尝试这个...

对于 JQuery:var total_goals = $("dataDAY1").html();

对于 Javascript:var total_goals = document.getElementById("dataDAY1").innerHTML;

片段:

var total_goals = $('#dataDAY1').html();
console.log(total_goals);

var total_goals_js = document.getElementById('dataDAY2').innerHTML;
console.log(total_goals_js);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="dataDAY1">Your Data From Php Variable</div>
<div id="dataDAY2">Your Data From Php Variable 2</div>

于 2020-02-28T05:33:14.117 回答
0

尝试这个:-

 var total_goals= <?php echo json_encode($json_array); ?>;
console.log(total_goals);
于 2020-02-28T05:03:07.133 回答
0

您可以在 javascript 中使用 php。见下面的代码

<script>
    var total_goals = "<?php echo $row['ipoSize']; ?>";
</script>
于 2020-02-28T05:31:55.570 回答