问题描述
|
我应该如何使用javascript做到这一点?我看了其他地方,但每个示例都使用Jquery。
仅在选择其他文本框中可见。
解决方法
假设您使用的是Rails的较旧版本,该版本具有作为js库的原型。
在选择列表的onchange事件中,添加javascript函数以显示包含文本框的div(假设您显示选择列表的值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>