我有这样的代码:
$.each(data.step_2, function (i, item) {
var date_php = '<?= strftime('%A, %d %b %Y',strtotime("2016-11-22")); ?>'; //i want change it
var arr = item.arrival_time === null ? '-' : item.arrival_time;
trHTML += '<tr><td>' + date_php + '</td><td>' + item.departure_time +
'</td><td>' + arr + '</td><td><input type="radio" name="pilihan" id="pilihan" value="'
+ item.schedule_id +'"></td></tr>';
// item.schedule_date
});
我想将“strtotime("2016-11-22"));
”更改为 strtotime("item.schedule_date"));
那个“ item.schedule_date
”我从ajax数据中获取。
如何组合?
最佳答案
在 javascript 中要使用 strftime,您必须使用外部 javascript 库。例如我使用以下库:http://hacks.bluesmoon.info/strftime/demo.html (下载此脚本以包含到您的开发服务器中)
这是我的代码:
<script src="http://hacks.bluesmoon.info/strftime/strftime.js"></script>
<script>
var date_php = '<?= strftime('%A, %d %b %Y',strtotime("2016-11-22")); ?>';
alert(date_php); //converted using php
var d = new Date("2016-11-22");
var ymd = d.strftime('%A, %d %b %Y');
alert(ymd); //converted using javascript
</script>
关于php - 将 php 语法与 ajax 结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40733128/