2011-05-26 39 views
0

我應該如何使用javascript?我看了其他地方,但每個例子都使用Jquery。從下拉列表中選擇其他顯示文本字段:ROR

只有在選擇其他文本框應該可見。

+0

的哪個版本ROR?如果是3.0.x,那麼你應該升級到3.1並使用jQuery,因爲它成爲默認的JS引擎。 (請參閱[這裏](http://weblog.rubyonrails.org/2011/5/22/rails-3-1-release-candidate)) – 2011-05-26 20:57:02

+0

我使用舊版本2.3.x – user659068 2011-05-27 14:24:56

回答

0

假設您使用的是具有原型作爲js庫的舊版rails。

在選擇列表中的onchange事件

添加JavaScript函數來顯示包含文本框格(假設你顯示選擇列表中的值5在文本框中):

<select id="select_item" name="select_item" onchange="display_date_range(this);"> 
... where 5 is the value of the option that needs to show text box 
</select> 

    function display_date_range(list) { 
    if(list.options[list.selectedIndex].value == 5) { 
     $("text_div").show(); 
    } 
    else { 
     $("text_div").hide(); 
    } 
    } 

<div id="text_div"><input type="text" value="Hooraaahhh..." /></div> 
相關問題