dsbckxk165039 2017-02-04 19:01
浏览 80
已采纳

从日期php中设置datepicker jquery中的日期,奇怪的值

I'm working with datepicker as follows:

<?php 

$sql="SELECT date FROM user WHERE id='$id_p' ;";
$result= query($sql);
/*Code for query in postgresql */

$date1=date_create($row['date']);
$date2=date_format($date1, 'd/m/Y');
$date3=$row['date'];
?>

<div class="form-group ">
    <label>Date *</label><br>
    <input id="date1" type="text" class="form-control required" >
    <input type="hidden" id="date3" name="datealt">
</div>

<script>
$(function () {
    $.datepicker.setDefaults($.datepicker.regional["es"]);
    $("#fechaV").datepicker({
        firstDay:1,
        currentText: 'Hoy',
        monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
        dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié;', 'Juv', 'Vie', 'Sáb'],
        dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        altFormat:'yy/mm/dd'          
    });
});

var date1=<?php echo $date2;?>;
var date3=<?php echo $date3;?>;
console.log(date1);
console.log(date3);
$("#date1").attr("value", date1);
$('#date3').attr("value",date3);
</script>

My problem is that when printing the dates in the script, it takes strange values, I can notice it when printing in the console and set the datepicker. However, on seeing the code portion, I can see these have the correct value.

That is, in my code, the variables take the values:

var date1=01/01/2016;
var date3=2016-01-01;

In the console.log:

0.000496031746031746
2014

What is wrong?

PD: probably missing segments of code or some names do not match, but it was time to transcribe the code to write the problem. Sorry for my english level

  • 写回答

2条回答 默认 最新

  • douyou8266 2017-02-04 19:07
    关注

    Try this first:

    var date1="<?php echo $date2;?>";
    var date3="<?php echo $date3;?>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'
  • ¥15 vue+element项目中多tag时,切换Tab时iframe套第三方html页面需要实现不刷新
  • ¥50 深度强化学习解决能源调度问题