如何添加onchange事件以选择Rails中的标签 [英] How to add an onchange event to select tag in rails

查看:88
本文介绍了如何添加onchange事件以选择Rails中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在此处添加onchange事件?

How do I add an onchange event here?

框架:导轨
数据库:MySQL

Framework: rails
Database: MySQL

我正在从数据库中填充选项,这使我不得不使用options_from_collection_for_select

I am populating the options from the database and that made me use options_from_collection_for_select

select_tag(:variable,options_from_collection_for_select(:all, :id, :name))

推荐答案

select_tag options哈希作为其最终参数,您可以在其中添加用于select的任何HTML属性.因此,添加一个onchange属性:

select_tag takes an options hash as its final parameter, in which you can add any HTML attributes for the select. So to add an onchange attribute:

select_tag :variable, options_from_collection_for_select(:all, :id, :name), :onchange => 'your_onchange_handler()'

这篇关于如何添加onchange事件以选择Rails中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆