我有一个 collection_select 字段,我想在更改后使 div 可见或不可见,具体取决于新值。
我有以下用于 collection_select 字段的代码,有一个 JS 函数 change_div_visibility 目前接受一个 div 名称,但我也想传入 collection_select 值。
如何将 collection_select 字段的当前值也发送到 change_div_visibility 函数?
<%= collection_select(:entry, :entry_status_id, EntStatus.find_all_draft_or_edit, :status, :en_desc, {}, {:onchange => "change_div_visibility('entry_set_editor')"}) %>
最佳答案
<select>
的值将在this.value
,所以试试这个:
<%= collection_select(:entry, :entry_status_id,
EntStatus.find_all_draft_or_edit, :status, :en_desc, {},
{ :onchange => "change_div_visibility('entry_set_editor', this.value)" })
%>
关于javascript - rails : Make a div element visible/invisible with onchange after changing a collection_select field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3778600/