2011-05-26 69 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>