将类 ID 分配给输入字段
所以我在rails中有这段代码
<%= f.label :year, "Year:" %><br />
<%= f.text_field :year %></p>
,它在html中返回这样的代码,
< input id="car_year" name="car[year]" size="30" type="text" class="hasDatepicker"><br />
看到class =“hasDatepicker”吗?我使用jquery获取日历来选择日期 这个运行良好,
但这是另一个(使用meta_search https://github.com/ernie/meta_search)
<td>
<%= f.label :year_gte, "Years from" %><br />
<%= f.text_field :year_gte, :size => 8 %></td>
输出像这样的 html 代码
< input id="search_year_gte" name="search[year_gte]" size="8" type="text"><br />
,显然这个缺少需要 jquery 来显示日历的 class="hasDatepicker"
问题是:如何让类内容显示在该字段中 感谢大家抽出时间。
更新2 我刚刚发现问题,我需要在我的视图中为 search_year_gte 编写一个 javascript 代码,因为我有一个用于 car_year 的代码 看起来像
<script>
$(function() {
$( "#search_year_gte" ).datepicker({
dateFormat: 'yy-mm-dd',
yearRange: '1980:2012',
changeMonth: true,
changeYear: true
});
});
</script>
<script>
$(function() {
$( "#search_year_lte" ).datepicker({
dateFormat: 'yy-mm-dd',<br />
yearRange: '1980:2012',<br />
changeMonth: true,
changeYear: true
});
});
</script>
,但我可以只使用一个脚本来处理这两个值吗? 对于 search_year_lte 和 search_year_gte
so there I have this code in rails
<%= f.label :year, "Year:" %><br />
<%= f.text_field :year %></p>
that returns in html a code like this one
< input id="car_year" name="car[year]" size="30" type="text" class="hasDatepicker"><br />
see the class="hasDatepicker"? I use the jquery to get the calendar to select dates
this one is working good
but here is another one (using meta_search https://github.com/ernie/meta_search)
<td>
<%= f.label :year_gte, "Years from" %><br />
<%= f.text_field :year_gte, :size => 8 %></td>
that outputs an html code like this one
< input id="search_year_gte" name="search[year_gte]" size="8" type="text"><br />
obvius this one is missing the class="hasDatepicker" that needs the jquery to display the calendar
The question is: How do I get the class thing to display in that field
Thanks all for your time.
Update 2
I just found the problem I need an javascript code in my view for search_year_gte as I have one for car_year
looks like
<script>
$(function() {
$( "#search_year_gte" ).datepicker({
dateFormat: 'yy-mm-dd',
yearRange: '1980:2012',
changeMonth: true,
changeYear: true
});
});
</script>
<script>
$(function() {
$( "#search_year_lte" ).datepicker({
dateFormat: 'yy-mm-dd',<br />
yearRange: '1980:2012',<br />
changeMonth: true,
changeYear: true
});
});
</script>
but can I just use one script for both values?
for search_year_lte and search_year_gte
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试将类添加为属性?
如果需要,请查看文档了解可以传递给 text_field 帮助器的属性。
Did you try adding the class as an attribute?
Have a look at the documentation if you want to know what attributes you can pass to the text_field helper.