select_tag in rails about selected not change and onchange()

本文介绍了如何使用JavaScript简化表单选择器的配置过程,包括如何在选择器变化时立即提交表单,以及如何根据用户的选择动态更新表单元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

make it more easy after http://www.cnblogs.com/juandx/p/4058399.html

1  if you want the selected is what you choose after you submit the form use javascripts, then you should do this  selected: params[:option] in options_for_select();

2  if you want to submit after you change the select tag immediately,you should use onchange: "this.form.submit();"  ofcouse the ";"  is not necessary;

 

<%= form_tag("monitor",:id => "idform",name: "idform",method: "get") do |f| %>
  时间间隔:
  <%= select_tag :times, options_for_select([["second","_10seconds"],["minute","_5minutes"],["hour","_hour"],["day","_day"],["week","_week"],["month","_month"],["year","_year"]] , selected: (params[:times]==nil ? "_5minutes" : params[:times]) ), onchange: "this.form.submit();" %>
        
  列数:
  <%= select_tag :col, options_for_select([["1","1"],["2","2"],["3","3"],["4","4"],["5","5"],["6","6"],["7","7"],["8","8"],["9","9"],["10","10"]], selected: (params[:col]==nil ? 2 : params[:col]) ), onchange: "this.form.submit();" %>
     
  <%= submit_tag("刷新") %>
<% end %>

  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值