如何执行代码继续使用Javascript中的引号

时间:2018-02-06 06:47:15

标签: javascript

我正在使用一个自动刷新图像的简单脚本,正在刷新的图像是一个代表流量的实时图形,用于抽取我在PHP中使用日期的时间和日期。基本上它看起来像这样。

<?php
date_default_timezone_set("America/Los_Angeles");
$lastday = date("Y-m-d-H-i-s",strtotime("-1 days"));
$today = date("Y-m-d-H-i-s");
?>
</style>
<script type='text/javascript'>
      var lastday="<?php echo $lastday; ?>";
      var today="<?php echo $today; ?>";
      document.write(lastday);
window.setInterval(function() {
    var d = new Date();
    $("#myimg").attr("src", "http://192.168.10.35/chart.png?graphid=-1&id=8459&avg=60&sdate=document.write(lastday);&edate=document.write(today);&hide=-4,4&clgid=&width=520&height=215&graphstylefile=graphstyling.htm&animationandinteraction=1&datastylefile=graphdatastyling.htm&animationstylefile=graphanimationstyling.htm&graphstyling=baseFontSize=%2711%27%20showLegend=%270%27%20tooltexts=%271%27&datastyling=drawAnchors=%271%27%20anchorRadius=%271%27%20lineThickness=%272%27&refreshable=true?"+d.getTime());
}, 2000);
</script>

现在看看这一行,(12)

$(“#myimg”)。attr(“src”,“http://192.168.10.35/chart.png?graphid=-1&id=8459&avg=60&sdate= document.write(lastday);&amp; edate = document.write(today) ; &安培;隐藏= -4,4-&安培; clgid =安培;宽度= 520&安培;高度= 215安培; graphstylefile = graphstyling.htm&安培; animationandinteraction = 1&安培; datastylefile = graphdatastyling.htm&安培; animationstylefile = graphanimationstyling.htm&安培; graphstyling = baseFontSize =%2711%27%20showLegend =%270%27%20tooltexts =%271%27&安培; datastyling = drawAnchors =%271%27%20anchorRadius =%271%27%20lineThickness =%272%27&安培;刷新=真“+ d.getTime());

代码中的粗体部分是php中的日期,问题是自document.write(lastday)以来代码没有运行;在引号内,不显示图表。

使用像这样的代码

$("#myimg").attr("src", "http://192.168.10.35/chart.png?graphid=-1&id=8459&avg=60&sdate=" + document.write(lastday); + "&edate=" + document.write(today); + "&hide=-4,4&clgid=&width=520&height=215&graphstylefile=graphstyling.htm&animationandinteraction=1&datastylefile=graphdatastyling.htm&animationstylefile=graphanimationstyling.htm&graphstyling=baseFontSize=%2711%27%20showLegend=%270%27%20tooltexts=%271%27&datastyling=drawAnchors=%271%27%20anchorRadius=%271%27%20lineThickness=%272%27&refreshable=true?"+d.getTime());

是不可能的,因为代码将在第一个引用中结束。 任何想法我怎样才能使它发挥作用?

谢谢!

1 个答案:

答案 0 :(得分:0)

首先,谁给出负面声誉。请提供解释,因为新用户不会理解他们正在做什么问题。 接下来针对上述问题的解决方案是你可以通过在Javascript中使用PHP使用纯Javascript其他方式来做两件事。 在Javascript中使用PHP的解决方案

您不需要使用document.write,因为它将在同一网页上打印,不会产生任何输出。您可以直接在字符串中使用JS变量,如下面的

$("#myimg").attr("src", "http://192.168.10.35/chart.png?graphid=-1&id=8459&avg=60&sdate=" + lastday + "&edate=" + today + "&hide=-4,4&clgid=&width=520&height=215&graphstylefile=graphstyling.htm&animationandinteraction=1&datastylefile=graphdatastyling.htm&animationstylefile=graphanimationstyling.htm&graphstyling=baseFontSize=%2711%27%20showLegend=%270%27%20tooltexts=%271%27&datastyling=drawAnchors=%271%27%20anchorRadius=%271%27%20lineThickness=%272%27&refreshable=true?"+d.getTime());

其他解决方案是您只能在Javascript中使用日期,然后执行上述操作。日期可以通过Javascript的日期功能进行。