[英]Passing parameter to onchange of select in Rails
<%= f.select :id, options_from_collection_for_select( @rtypes, "id", "typeName"), {include_blank: true }, :onchange => ShowSubTypes() %>
在這里,我有選擇的選項,我想要的是將id作為參數傳遞給ShowSubTypes()
函數。 我的@rtypes
變量返回一個數組,因此我不能只傳遞@rtypes.id
。
<%= f.select :id, options_from_collection_for_select(
@rtypes, "id", "typeName"),
{include_blank: true },
:onchange => "ShowSubTypes($(this).val())" %>
基本上,您可以通過Javascript完成此操作。 this
所述的onChange的上下文中是<select>
輸入。 我假設jQuery獲得與@rtypes的“ id”相對應的所選選項的值。
用普通的Javascript,我認為是this.value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.