小编cha*_*ez1的帖子

来自<input type = date>的JavaScript日期对象

我正在尝试在focus.add_days函数中创建一个javascript日期对象,以便在元素中的给定日期添加一些日期.问题是javascript对象不期望字符串"Ymd"所以如何创建日期对象而不将字符串"Ymd"解析成片段,或者是唯一的方法?

trigger = {
fecha_ini: function(){
    $('input[name="fecha_ini"]').on('change',function(){
      console.log('hi');
      var fecha_fin = $(':input [name=fecha_fin]');
      var min = $(this).val();
      //here is where i pass the "Y-m-d" string as the date argument
      var max = fechas.add_days(min,31*4);
      fecha_fin.attr('min',min);
      fecha_fin.attr('max',max);
      fecha_fin.val('');
    })
  }
};

fechas = {
  add_days: function addDays(date, days) {
    //here is where i use the string "Y-m-d" to create the date object, but obviusly doesnt work
    var result = new Date(date);
    result.setDate(date.getDate() + days);
    return result;
}
};

trigger.fecha_ini();
Run Code Online (Sandbox Code Playgroud)

javascript html5 date input object

9
推荐指数
3
解决办法
7774
查看次数

标签 统计

date ×1

html5 ×1

input ×1

javascript ×1

object ×1