localhost和托管之间的Javascript差异

I have a php page that has some javascript, and for some reason the '<% ... %>' tags are behaving differently locally versus hosted. The relevant portion of code from my page is:

<script>

    var options = {
        segmentShowStroke: false,
        animateRotate: true,
        animateScale: false,
        percentageInnerCutout: 50,
        tooltipTemplate: "<%= value %>%",
        responsive: true,
        multiTooltipTemplate: '<%= datasetLabel %> - <%= value %>',
        labelsFilter: function (value, index) {
            return (index + 1) % 5 !== 0;
        }
    }

Locally, when I use firebug, I see this (which I want to see):

    var options = {
        segmentShowStroke: false,
        animateRotate: true,
        animateScale: false,
        percentageInnerCutout: 50,
        tooltipTemplate: "<%= value %>%",
        responsive: true,
        multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>",


        labelsFilter: function (value, index) {
            return (index + 1) % 5 !== 0;
        }
    }

However when I put the page on my domain, and use firebug, I see this:

    var options = {
        segmentShowStroke: false,
        animateRotate: true,
        animateScale: false,
        percentageInnerCutout: 50,
        tooltipTemplate: "value%",
        responsive: true,
        multiTooltipTemplate: "datasetLabel - value",


        labelsFilter: function (value, index) {
            return (index + 1) % 5 !== 0;
        }
    }

It looks like 'tooltipTemplate' and 'multiTooltipTemplate' are being evaluated once before runtime when it is hosted, which is leading to unexpected results (hardcoded 'datasetLabel - value' instead of something like 'Net Worth - 100,000'

the tags have changed with different php versions. you probably have different versions installed on the different systems.

use the <?php opening tag, which is available on all versions.


the following ASP tags <% , %> , <%= have been removed with php 7.

7.0.0 ASP tags <% , %> , <%= , and script tag are removed from PHP.

<?= can be used as of php 5.4.0

5.4.0 The tag <?= is always available regardless of the short_open_tag ini setting.

see PHP tags