在下拉列表中选择其他显示文本字段:ROR

问题描述

| 我应该如何使用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>
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...