0

我有全局变量:

          units = 0;
          majorUnits = 0; 
          supportUnits = 0;
          requiredUnits = 0;
          electiveUnits = 0;
          electiveUnitsStop = 0;
          pending = 0;
          percent = 0;
          supportPercent = 0;
          requiredPercent = 0;
          electivePercent = 0;

我在函数上使用这个变量:

      $("tr").click(function() {
        $(this).toggleClass("taken");
        if ( $(this).hasClass('taken') ) 
        { .....

然后我有第二个函数,在其中我将变量设置为零:

      $( "#clear-button" ).click(function() {
          units = 0;
          majorUnits = 0; 
          supportUnits = 0;
          requiredUnits = 0;
          electiveUnits = 0;
          electiveUnitsStop = 0;
          pending = 0;
          percent = 0;
          supportPercent = 0;
          requiredPercent = 0;
          electivePercent = 0;
          // $( "tr" ).click(); 
          //$("tr").find('taken').removeClass('taken');
          //$("table").closest('tr').find('.taken').removeClass('taken');
          //$("tr").removeClass();
          //taken.allInstances = [];
        });

如上面在注释代码中所见,我正在尝试删除所有出现taken在我的 html 表的行中可能存在或不存在的类。

我怎么能做到这一点?!?!

我真的很感激任何帮助。

4

1 回答 1

0

您是要删除还是元素

从子元素中删除类:

$('table#tablename .taken').removeClass('taken');

http://api.jquery.com/removeClass/

完全删除元素:

$('table#tablename .taken').remove();

http://api.jquery.com/remove/

此外,根据您的 HTML 结构,您可以更具体地定位和使用this,而不是指定表名(也使用findclosest

于 2013-11-04T04:11:39.467 回答