簡體   English   中英

在Rails中將參數傳遞給select的onchange

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM