dsbckxk165039
2017-02-04 19:01
浏览 79

从日期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

图片转代码服务由CSDN问答提供 功能建议

我正在使用datepicker,如下所示:

 &lt  ;?php 
 
 $ sql =“SELECT date FROM user WHERE id ='$ id_p';”; 
 $ result = query($ sql); 
 / * postgresql中的查询代码* / 
 \  n $ date1 = date_create($ row ['date']); 
 $ date2 = date_format($ date1,'d / m / Y'); 
 $ date3 = $ row ['date']; 
?  &gt; 
 
&lt; div class =“form-group”&gt; 
&lt; label&gt;日期*&lt; / label&gt;&lt; br&gt; 
&lt; input id =“date1”type =“text”class  =“需要表单控制”&gt; 
&lt; input type =“hidden”id =“date3”name =“datealt”&gt; 
&lt; / div&gt; 
 
&lt; script&gt; 
 $(function(  ){
 $ .datepicker.setDefaults($ .datepicker.regional [“es”]); 
 $(“#fechaV”)。datepicker({
 firstDay:1,
 currentText:'Hoy',\  n 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 =&lt;  ?php echo $ date2;?&gt ;; 
var date3 =&lt;?php echo $ date3;?&gt ;; 
console.log(date1); 
console.log(date3); 
 $(“#date1”  ).attr(“value”,date1); 
 $('#date3')。attr(“value”,date3); 
&lt; / script&gt; 
   
 
  

我的问题是,在脚本中打印日期时,它需要奇怪的值,我可以在控制台中打印并设置日期选择器时注意到它。 但是,在看到代码部分时,我可以看到它们具有正确的值。

也就是说,在我的代码中,变量采用值: < pre> var date1 = 01/01/2016; var date3 = 2016-01-01;

在console.log中:

  0.000496031746031746 
2014 
   
 
 

有什么问题?

PD:可能缺失 代码段或某些名称不匹配,但是是时候转录代码来编写问题了。 对不起我的英语水平

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyou8266 2017-02-04 19:07
    已采纳

    Try this first:

    var date1="<?php echo $date2;?>";
    var date3="<?php echo $date3;?>";
    
    点赞 评论
  • dsio68964998 2017-02-04 19:09

    You need to put your vars between quotes:

    var date1 = '<?php echo $date2;?>';
    var date3 = '<?php echo $date3;?>';
    
    点赞 评论

相关推荐 更多相似问题