【问题标题】:Retrieve the value of the select option in a View检索视图中选择选项的值
【发布时间】:2016-07-09 22:52:26
【问题描述】:

我的观点如下:

<%= select_tag(:option_id, options_for_select([
                     ['Students', 1],
                     ['Teachers', 2],
                     ])) %>

如何在视图本身中检索选定的值?我想根据它动态改变&lt;%= link_to %&gt;的值。

这是我的部分咖啡脚本:

jQuery ->
  $('#import_type').change ->

我现在如何更改&lt;%= link_to %&gt; 的值?

【问题讨论】:

    标签: jquery ruby-on-rails-4


    【解决方案1】:

    你可以这样做:

    jQuery ->
      $('#import_type').change ->
        if $('#import_type').val() == '1'
          $('#link_to_id').attr("attribute", "value")
    

    确保将 link_to_id 替换为实际 ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      相关资源
      最近更新 更多