Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Rails-日期输入格式?_Javascript_Html_Ruby On Rails_Date_Ruby On Rails 4 - Fatal编程技术网

Javascript Rails-日期输入格式?

Javascript Rails-日期输入格式?,javascript,html,ruby-on-rails,date,ruby-on-rails-4,Javascript,Html,Ruby On Rails,Date,Ruby On Rails 4,rails中是否有方法覆盖表单中的默认日期输入? 在html表单中,我将日期输入作为下拉菜单。事情是这样的,它只显示了从2008年到2018年的年份。我怎样才能让它让我进入任何一年,我想,但保持月和日作为dropbox? 我尝试在html表单中使用type=“date”,但没有任何变化 在rails中修改日期输入格式的最佳方法是什么(如果还需要更改,还可以使用html/javascript)?您可以使用start\u year和end\u year选项。默认情况下,范围为当前年-5和当前年+5

rails中是否有方法覆盖表单中的默认日期输入? 在html表单中,我将日期输入作为下拉菜单。事情是这样的,它只显示了从2008年到2018年的年份。我怎样才能让它让我进入任何一年,我想,但保持月和日作为dropbox? 我尝试在html表单中使用type=“date”,但没有任何变化


在rails中修改日期输入格式的最佳方法是什么(如果还需要更改,还可以使用html/javascript)?

您可以使用
start\u year
end\u year
选项。默认情况下,范围为
当前年-5
当前年+5

date_select("post", "updated_on", start_year: 1995, end_year: 2013)

阅读更多选项

您可以编写自己的助手:

def date_year_text_field(object_name, method)
  html = select_day(Date.today, :field_name => "#{object_name}[#{method}(3i)]")
  html << select_month(Date.today, :field_name => "#{object_name}[#{method}(2i)]")
  html << text_field_tag("#{object_name}[#{method}(1i)]", Date.today.year.to_s, :length => 4)
end
def date\u year\u text\u字段(对象名称、方法)
html=选择_day(Date.today,:字段_name=>“#{object_name}[#{method}(3i)]”)
html“#{object_name}[#{method}(2i)]”)
html 4)
结束
也许可以帮助您开发自己的助手。