【问题标题】:How to add jquery variable data in php statement? [duplicate]如何在php语句中添加jquery变量数据? [复制]
【发布时间】:2017-02-06 05:24:49
【问题描述】:

我被这个问题困住了。我想用 jquery 做

window.newdatevalue = '<?php echo date("Y-m-d") ?>';// this date is dynamic

var newdate = window.newdatevalue;

console.log(newdate); // when i print this it give me right result -2017-02-06 

var finaldate = "<?php echo date('d/M/y',strtotime('"+newdate+"'))?>";

console.log(finaldate); // but when i print this it give me wrong result 01/Jan/70 

谁能帮我看看我做错了什么

【问题讨论】:

  • 尝试将 finaldate 格式更改为 "Y-m-d" [ echo date("Y-m-d",strtotime('"+newdate+"')) ]
  • 我试过了,但它不起作用@SarangaR
  • PHP 在服务器上执行,然后服务器将页面发送到浏览器,然后运行 ​​javascript。你不能只在 PHP 中注入一个 javascript 变量,为时已晚
  • 我认为,您以任何方式误解了服务器端编程的一些原则,我认为您希望以下回答 [ echo date("d/m/Y",strtotime(date('Y-m-d') )); ] 或 [ 回显日期('d/m/Y'); ]

标签: javascript php jquery


【解决方案1】:

可以试试这个。它可能会对你有所帮助。

window.newdatevalue = '<?php echo date("d-m-Y", strtotime(date("Y-m-d"))); ?>'

console.log(window.newdatevalue);

【讨论】:

  • $originalDate 在哪里;
  • 更新了我的答案
  • 我在不同的日子有不同的日期。所以我想在 strtotime 中放置变量
  • 你在上面的意思...请更清楚地说明
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-21
  • 1970-01-01
  • 1970-01-01
  • 2013-01-15
  • 1970-01-01
  • 1970-01-01
  • 2020-11-28
相关资源
最近更新 更多