Multiple dynamic instances of bootstrap-timepicker

情到浓时终转凉″ 提交于 2020-01-16 19:01:06

问题


I am using the bootstrap-timepicker for rails and I am using it in a form helper. It works very well if there is only one instance of it. Here is a code fragment:

<div class="bootstrap-timepicker input-append span2 offset0">
  <%= f.label :to_hour %>
  <input id="timepicker1" type="text" class="input-small" value='12:15 PM'>
  <span class="add-on"><i class="icon-time"></i></span>
</div>

However it doesn't work when there are multiple instances of it in a single page. Essentially I have multiple dynamic rows of data that require a time picker each and the examples that I have found were simple and had a unique input id and corresponding javascript.

Does anyone know how I can make this dynamic or know of any examples that demonstrates this?


回答1:


Don't use an ID at all. Use a class:

<input type="text" class="input-small timepicker" value='12:15 PM'>

And in your JS:

$(".timepicker").timepicker(...);


来源:https://stackoverflow.com/questions/16807554/multiple-dynamic-instances-of-bootstrap-timepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!