【问题标题】:Problem with Javascript onchange event in Ruby on RailsRuby on Rails 中的 Javascript onchange 事件问题
【发布时间】:2009-09-30 08:24:49
【问题描述】:

我将这段代码放在 index.html(上传控制器)中,这是一个示例。

<p>
    <label for="picture_city">City:</label>
<%= form.select :city, Picture::CITIES, :onchange => remote_function(:url => {:action => 'update_universities'}, :with => '') %>
 </p>

当我去上传/索引表单加载良好且没有错误。但是当我在 html 中看到生成的代码时,我看不到 onchange 属性。很神秘,请帮我解决这个问题!

<p>

    <label for="picture_city">City:</label>
<select id="picture_city" name="picture[city]"><option value="1">New York</option>
<option value="2">Boston</option>
<option value="3">Chicago</option>
<option value="4">Detroit</option>
<option value="5">Washington</option></select>
 </p>

问题出在哪里??? 有人知道吗?

【问题讨论】:

    标签: javascript ruby-on-rails


    【解决方案1】:

    正确形成的选择格式:

    select(object, method, choices, options = {}, html_options = {})
    

    类似的东西:

    <%= form.select :obj, :city, Picture::CITIES, {:onchange => remote_function(:url => {:action => 'update_universities'}, :with => '')} %>
    

    【讨论】:

    • 它没有帮助。我在 html 源代码中仍然看不到 onchage 属性。
    • 也许应该在这里使用文字来命名属性?选择 .... :html_options => { :onchange => 'alert("asd");' }
    • Anatoliy 我不明白你在说什么。
    • Tolyan 我刚刚让它正常工作。所以,非常感谢你的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多