RoR remote_function传递元素的类名

时间:2010-09-02 05:17:54

标签: ruby-on-rails

remote_function中如何传递表单元素的className

我有以下代码,

<%=link_to(content_tag('span',t('country.name')),'#',
   {:title=>t('country.name'),**:class=>"change_list"**,
    :onclick=>remote_function(:url => {:action => :change_view},
    :with =>"'**change**=**'+ ?????"**)}) %>

所以,在onclick上,我想传递参数:change,其值为:class=>"change_list"

感谢,

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望在Ajax请求中传递anchor标记的类名,那么以下内容应该有效(重新格式化以尝试提高可读性):

<%= link_to(
      content_tag('span', t('country.name')), 
      '#',
      { :title   => t('country.name'),
        :class   => "change_list", 
        :onclick => remote_function(
        :url     => {:action => :change_view}, 
        :with    => "'change=' + this.className"
        )
      }) 
%>