How to replace date on a jQuery countdown script with a PHP variable?
How can this script is modified to accept a php variable instead in the place of writing date:"august 12, 2011 23:59"
?
<script type="text/javascript">
$(document).ready(function() {
$("#time").countdown({
date: "august 12, 2011 23:59",
开发者_StackOverflow onComplete: function( event ){
$(this).html("Completed");
},
leadingZero: true
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#time").countdown({
date: "<?php echo $variable; ?>",
onComplete: function( event ){
$(this).html("Completed");
},
leadingZero: true
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#time").countdown({
date: "<?=$myvariable?>",
onComplete: function( event ){
$(this).html("Completed");
},
leadingZero: true
});
});
</script>
Is your js parsed by php first? if so its just a matter of passing the correct date format.
to get the same format as above you can use
strftime("%B %d, %Y %H:%M");
So your code block would look like
<script type="text/javascript">
$(document).ready(function() {
$("#time").countdown({
date: "<?php echo strftime("%B %d, %Y %H:%M");?>",
onComplete: function( event ){
$(this).html("Completed");
},
leadingZero: true
});
});
</script>
Try this, you need to format the date as per your need on the server side itself.
$(document).ready(function() {
$("#time").countdown({
date: "<? =date("Y/m/d") ?>",
onComplete: function( event ){
$(this).html("Completed");
},
leadingZero: true
});
});
If what you want is an AJAX call, you should do the following:
<script type="text/javascript">
$(document).ready(function() {
$.get('path/to/php/date', function(date) {
$("#time").countdown({
date: date,
onComplete: function( event ){
$(this).html("Completed");
},
leadingZero: true
});
});
});
</script>
Make sure that the php script at "path/to/php/date" returns the date you want.
精彩评论