gpt4 book ai didi

ruby-on-rails - 插入一个 css 类以在 Rails date_select 上进行选择

转载 作者:行者123 更新时间:2023-12-02 02:29:53 25 4
gpt4 key购买 nike

我正在使用 date_select 方法生成 3 个 html 选择,日、月和年。但我需要每个选择都有一类 CSS。

我没有在文档中找到如何将参数传递给助手,我尝试了几种方法但没有找到。

rails View :

<%= f.date_select :birthday, :order => [:day, :month, :year], :start_year => 1910, :end_year => 2012, :html => {:class => ['day', 'month', 'year']} %>

HTML 输出:

<select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]">
<select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]">
<select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]">

像我一样的 HTML 输出:

<select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]" class="day">
<select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]" class="month">
<select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]" class="year">

谢谢!

最佳答案

我解决这个问题的方法是使用 css

查看

<span class="datetime"> <%= f.date_select :birthdate, :order => [:day, :month, :year], :start_year => 1910, :end_year => 2012 %></span>

CSS

.datetime select:nth-child(1){
width: 130px;
text-indent: 15px;
}

.datetime select:nth-child(2) {
width: 200px;
text-indent: 5px;
}

.datetime select:nth-child(3) {
width: 110px;
text-indent: 15px;
}

关于ruby-on-rails - 插入一个 css 类以在 Rails date_select 上进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10031404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com