简体   繁体   English

在HTML中传递javascript选项

[英]passing javascript options in HTML

I am using ruby gem bootstrap-datepicker-rails in my Rails-4 application, to draw a form for taking from_date and till_date as input as following. 我在我的Rails-4应用程序中使用ruby gem bootstrap-datepicker-rails ,绘制一个表单,将from_datetill_date作为输入,如下所示。 The beauty of this code is no javascript is needed as that in encoded in this gem's code. 这段代码的优点是不需要javascript,就像在这个gem的代码中编码一样。

<div class=" input-daterange" id="datepicker" data-provide='datepicker'>
  <label>From Date</label>
  <input type="text" class="form-control" name="from_date" id="from_date">

  <label>Till Date</label>
  <input type="text" class="form-control" name="till_date" id="till_date">
</div>

By default it takes format as “mm/dd/yyyy”, I want to change it to “yyyy-dd-mm”, Is it possible to do this by passing this in html options only and not using any javascript for it. 默认情况下,格式为“mm / dd / yyyy”,我想将其更改为“yyyy-dd-mm”,是否可以通过仅在html选项中传递此内容而不使用任何javascript来实现此目的。 I tried following and some other permutations of these, but of-course they didn't work. 我尝试了以下和其他一些排列,但当然它们没有用。

<div class=" input-daterange" id="datepicker" data-provide='datepicker' options='format:"yyyy-mm-dd"'>

<div class="row input-daterange" id="datepicker" data-provide='datepicker' format="yyyy-mm-dd" >

Please let me know if this is possible to do and how. 如果有可能,请告诉我。

The docs suggest you do it like this: 文档建议你这样做:

<input class="datepicker" data-date-format="mm/dd/yyyy">

https://bootstrap-datepicker.readthedocs.org/en/latest/#configuration https://bootstrap-datepicker.readthedocs.org/en/latest/#configuration

Note that the attribute goes on the input element and is called data-date-format 请注意,该属性位于input元素上,称为data-date-format

I think you are missing the right name of the html attribute, try : 我想你错过了html属性的正确名称,试试:

data-date-format="yyyy/mm/dd"

Source : documentation 资料来源:文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM