簡體   English   中英

如何顯示在文本字段中選擇的值?

[英]How can show a value selected into a text field?

我想顯示從文本框中選擇的選擇框中的值

<%= select_tag "customer_id", options_for_select(@customers.collect {|t| [t.correct_name,t.id]},params[:customer_id].to_i) %>

<%= f.text_field :customer,:value => @customer.id %>

我嘗試了此示例,但僅用於輸入。

嘗試這個:

$("#customer_id").on("change", function() {
  $(this).parent().find("input").val($(this).val());
});

更改您的text_field像這樣

<%= f.text_field :customer,:id => "customer",:value => "" %>

並嘗試一下

jQuery(function($){
    var $value = $('#customer');
    $('select[name="customer_id"]').change(function(){
        $value.val($(this).val())
    }).triggerHandler('change')
})

演示版

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM