javascript - 当 Ruby on Rails 中的 date_select 值更改时调用 javascript
问题描述
<%= date_select(:production_month, :date, order: [:month, :year], :start_year => @start_year, :end_year => @end_year) %>
我在我的 Rails 表单之一中有上述 date_select。
我希望在更改上述 date_selected 的值时调用 javascript 函数。
我在我的代码中编写了以下 javascript 块来处理这个问题:
$('#production_month').change(function () {alert("Yayyy!!!")});
但是无论我在 date_select 中选择什么值,这个 javascript 函数都不会被调用。
我在这里做错了什么?请帮忙!
解决方案
通过内置的 rails 方法可能更容易做到这一点:
Rails 3 & Ajax date_select onchange => 提交
date_select(object_name, method, options = {}, html_options = {})
在你的情况下:
<%= date_select(:production_month, :date, order: [:month, :year], :start_year => @start_year, :end_year => @end_year, html_options: { onchange: 'productionMonth();' } ) %>
编辑:或者使用我误读的正确方法名称:
<%= date_select(:production_month, :date, order: [:month, :year], :start_year => @start_year, :end_year => @end_year, html_options: { onchange: 'fire_on_product_change();' } ) %>
推荐阅读
- python - 如何使用 gspread python 将输出数据帧放置在 D2 而不是 A1 中的谷歌表格中
- vue.js - Vuetify如何覆盖分页组件的sass变量
- javascript - 如何传递文件的路径属性?反应
- xml - 在 xslt 样式表输出中保留实体而不使用字符映射
- python - 帕拉米科谈惠普供应
- python - 无法按照我的意愿调整列表
- r - 重新排列多个 GGPLOT2 图表和移动/调整比例时遇到问题
- python - Python子进程模块等待方法
- scala - 澄清为什么我不能通过它的子类型覆盖使用泛型类参数的方法
- sql-server - SSDT - 排除某些模式以及未命名的约束