【问题标题】:problem in rails with "cycle" over classes in a CSS and onmouseover, onmouseout在 CSS 和 onmouseover、onmouseout 类上“循环”的 Rails 问题
【发布时间】:2010-10-28 13:25:33
【问题描述】:

我的 index.html 中有这段代码:

<div id="users-list">
<tr class="<%= cycle('odd', 'even') %>" onmouseover="this.className='over';" onclick="location.href='<%= user_path(user) %>'" >

<td><%= user.surname %></td>
<td><%= user.name %></td>

</tr>
</div>  

作为表格的一部分,和这个关联的css:

#users-list  .odd {
    background: #00ffff;
}

#users-list .even {
    background: #ffffff;
}

#users-list .over {
    background: #00ccff;
}  

关键是要制作一个带有可点击行的表格,带有不同颜色的奇数行和偶数行,当鼠标悬停时它们会获得第三种颜色。问题出在代码的循环部分,如果我在 class="" 中只放一个循环,一切正常,我有奇数行和偶数行不同的颜色,但是当我过去然后用鼠标移出时,类值仍然是 onmouseover="this.className='over';" 设置的值。所以我决定像这样使用 onmouseout="this.className='';"

<tr class="<%= cycle('odd', 'even') %>" onmouseover="this.className='over';" onmouseout="this.className='<%= cycle('odd', 'even')%>';" onclick="location.href='<%= user_path(user) %>'" >  

这就是问题所在! cycle 中的每一个都停止工作,并且我始终将类设置为循环中两个参数中的第一个。 任何的想法?也许是一个错误?还是浏览器不兼容?我需要在 Chrome 上完成这项工作。感谢大家的任何建议

【问题讨论】:

    标签: javascript ruby-on-rails css onmouseover onmouseout


    【解决方案1】:

    每次调用cycle 都会切换类名。您在此行中有 2 个调用,这将导致 odd 值为第一个,even 为第二个。

    您应该在第二次调用(onmouseout)中使用current_cycle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-02
      • 2023-03-03
      • 1970-01-01
      • 2012-02-04
      • 2015-08-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      相关资源
      最近更新 更多