bootstrap-timepicker 的多个动态实例 [英] Multiple dynamic instances of bootstrap-timepicker
问题描述
我正在为 rails 使用 bootstrap-timepicker,我在表单助手中使用它.如果只有一个实例,它的效果会很好.这是一个代码片段:
<%= 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>
但是,当单个页面中有多个实例时,它不起作用.本质上,我有多个动态数据行,每行都需要一个时间选择器,我发现的示例很简单,并且具有唯一的输入 ID 和相应的 javascript.
有谁知道我如何使这种动态变得动态或知道任何可以证明这一点的例子?
根本不要使用 ID.使用类:
在你的 JS 中:
$(".timepicker").timepicker(...);
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?
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(...);
这篇关于bootstrap-timepicker 的多个动态实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!