这是我正在使用的代码,但似乎没有用,任何帮助将不胜感激。
PHP代码,
<?
$date = new DateTime($rdatetime);
$sdate1 = $date->format('M d, Y H:I:s');
echo $sdate1;
?>
Java脚本
<script type="text/javascript">
// Set the date we're counting down to
//var countDownDate = new Date("Jan 5, 2018 15:37:25").getTime();
var countDownDate = new Date('$sdate').getTime();
//var countDownDate = new Date("$sdate").getTime();
</Script>
我想将$ sdate1传递给$ sdate。希望我能够正确解释我的问题。
答案 0 :(得分:1)
<?
$date = new DateTime($rdatetime);
$sdate1 = $date->format('M d, Y H:I:s');
echo $sdate1;
?>
<script type="text/javascript">
// Set the date we're counting down to
//var countDownDate = new Date("Jan 5, 2018 15:37:25").getTime();
var countDownDate = new Date('<?=$sdate1;?>').getTime();
//var countDownDate = new Date("$sdate").getTime();
</script>
答案 1 :(得分:0)
你正在做的事情有点像hacky,但这会做你想做的事情:
<script type="text/javascript">
// Set the date we're counting down to
//var countDownDate = new Date("Jan 5, 2018 15:37:25").getTime();
var countDownDate = new Date('<?php echo $sdate ?>').getTime();
</Script>
答案 2 :(得分:0)
这是你的意思吗?将php变量传递给js
<?php
$date = new DateTime($rdatetime);
$sdate = $date->format('M d, Y H:I:s');
?>
<script type="text/javascript">
var countDownDate = new Date('<?php echo $sdate; ?>').getTime();
</script>
答案 3 :(得分:0)
您可以使用html隐藏输入来存储数据:
<input type="hidden" name="example" value="<?php echo $sdate1 ?>">
<script type="text/javascript">
var value = document.getElementsByName("example")[0].value;
//JQuery:
//var value = $('input[name=example]').val();
var countDownDate = new Date(value).getTime();
</script>
<span id="date" data-date="<?php echo $sdate1 ?>"><?php echo $sdate1 ?></span>
<script type="text/javascript">
var value = document.getElementById("searchTxt").getAttribute('data-date');
//JQuery:
//var value = $('input[name=example]').attr("data-date");
//var value = $('input[name=example]').data("date");
var countDownDate = new Date(value).getTime();
</script>