我想为rails中的datetime_select
字段添加客户端验证。rails中的datetime_select字段有不同的下拉菜单,用于选择年、月、日和时间,其中id的格式为start_date_1i
, start_date_2i
,…等等......如何使用这些id获取值并将其转换为jquery datetime对象。
我在应用程序中使用了这个标签
<%= f.datetime_select :start_date, {:default => { :hour => 17, :minute => 00 }, :ampm => true, :minute_step => 30}, {:required => true, :class => "start-time"} %>
它被转换成HTML格式,如下所示
<select id="banner_date_begin_1i" class="start-time" required="required" name="banner[date_begin(1i)]">
<select id="banner_date_begin_2i" class="start-time" required="required" name="banner[date_begin(2i)]">
<select id="banner_date_begin_3i" class="start-time" required="required" name="banner[date_begin(3i)]">
—
<select id="banner_date_begin_4i" class="start-time" required="required" name="banner[date_begin(4i)]">
:
<select id="banner_date_begin_5i" class="start-time" required="required" name="banner[date_begin(5i)]">
在text_field上使用DateTimePicker。查看http://xdsoft.net/jqplugins/datetimepicker/