选中/取消选中所有复选框在 IE8 中不起作用
此 JavaScript 代码在 IE8 中不起作用,但在 Firefox 和 Google Chrome 中起作用:
<% content_for :head do %>
<script type="text/javascript">
document.observe("dom:loaded", function(){
// Observe toggler
$('toggle_all').observe('change', function(){
var toggle = $('toggle_all').checked;
$$('.check_boxes').each(function(check){
check.checked = toggle;
});
})
})
</script>
<% end %>
<table>
<tr>
...
<th><%= check_box_tag "toggle_all", 1, false %></th>
...
</tr>
<% reset_cycle %>
<% @estudantes.each do |estudante| %>
<tr class="<%= cycle("even", "odd") -%>">
...
<td><%= check_box_tag("candidato_ids[]", estudante.id,
(checked = true if @vaga.candidato_ids.include?(estudante.id)), :class => 'check_boxes' ) %></td>
...
</tr>
<% end %>
</table>
<%= submit_tag t('others.call', :item => 'vaga') %>
</form>
有人可以帮助我吗?
This javascript code does not work in IE8, but works in Firefox and Google Chrome:
<% content_for :head do %>
<script type="text/javascript">
document.observe("dom:loaded", function(){
// Observe toggler
$('toggle_all').observe('change', function(){
var toggle = $('toggle_all').checked;
$('.check_boxes').each(function(check){
check.checked = toggle;
});
})
})
</script>
<% end %>
<table>
<tr>
...
<th><%= check_box_tag "toggle_all", 1, false %></th>
...
</tr>
<% reset_cycle %>
<% @estudantes.each do |estudante| %>
<tr class="<%= cycle("even", "odd") -%>">
...
<td><%= check_box_tag("candidato_ids[]", estudante.id,
(checked = true if @vaga.candidato_ids.include?(estudante.id)), :class => 'check_boxes' ) %></td>
...
</tr>
<% end %>
</table>
<%= submit_tag t('others.call', :item => 'vaga') %>
</form>
Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IE是一款出色的浏览器。我们必须将焦点从代码工作的复选框上移开。跨浏览器代码与 IE 不匹配,呵呵
编辑: 但将“更改”替换为“点击”也效果很好。
IE is a browser outstanding. We must take the focus off the checkbox for the code work. Cross-browser code is no match for IE, hehehhe
EDIT: but replace the 'change' for 'click' works well, too.