OnClick 事件不是 binding/firing

OnClick event not binding/firing

我正在尝试创建一个 select link 来触发当前页面上的所有复选框,但它不起作用只是重新加载页面。

file_items.js

$('a.select-all-current').click(function(e){
  e.preventDefault();
  alert(e);
  $('input:not(:checked)').each(function(index, element){
    $(element).click();
  });
  return false;
});

index.html.slim

...
.col-lg-6.pull-right.align-right
      .pull-right
        = link_to 'Deselect All', '#', class: 'label'
      .dropdown.col-lg-2.pull-right
        a#selectAllMenu.dropdown-toggle[ data-toggle='dropdown' aria-expanded='true']
          .label.select-all
            = "Select All  "
            span.caret.pull-right
        ul.dropdown-menu[role='menu'  aria-labelledby='selectAllMenu']
          li 
            | SELECT
          li
            hr
          li
            = link_to 'current page', '', class: 'select-all-current'
          li
            = link_to 'all files', '', class: 'select-all-files'
          li
            = link_to 'all untagged files', '', class: 'select-all-untagged'
...

您需要将代码包装在这样的文档就绪语句中。

$(function() { 
    $('a.select-all-current').click(function(e){
      e.preventDefault();
      alert(e);
      $('input:not(:checked)').each(function(index, element){
        $(element).click();
      });
      return false;
    });
});