Jquery addClass(),removeClass()函数不起作用

时间:2017-12-29 12:21:36

标签: javascript jquery html css ajax

$('.push').each(function(){
  if($(':first-child',this).hasClass( "activex" )){
    $(this).off().off('click').on('click',function(){
      var a = $(this).attr('id');
      $.ajax({
        type: "POST",
        url: "includes/rcart.php",
        data:{'pid': a},
        success: function(data){
          var a= parseInt($('.cart').text());
          if((data.indexOf("2")) >= 0){
            console.log(data);
            console.log('not removed'); 
          }else{
            a--;
            console.log('removed');
            $(this).children().removeClass('activex');
            $('.cart').text(a);
          }
        }
      });
      console.log(a); 
    });
  }else{
    $(this).on('click',function(){
      var a = $(this).attr('id');
      $.ajax({
        type: "POST",
        url: "includes/cart.php",
        data:{'pid': a},
        success: function(data){
          console.log(data);
          var a= parseInt($('.cart').text());
          if((data.indexOf("2")) >= 0){
            console.log('done'); 
          }else{
            a++;
            $('.cart').text(a);
            $(this).children().addClass('activex');
          }
        }
      });
      console.log(a); 
    });
  }
});

我正在尝试删除类activex,只要单击了类推的按钮但它不起作用且代码中没有错误,并且它不会删除类。如果我使用类.push在chrome控制台中手动删除该类,则可以正常工作。

我正在尝试删除类activex,只要单击了类推的按钮但它不起作用且代码中没有错误,并且它不会删除类。如果我使用类.push在chrome控制台中手动删除该类,则可以正常工作。

1 个答案:

答案 0 :(得分:0)

这是您更新的代码,我刚从您的代码中删除了children()。 让我知道它是否有帮助。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:param name="search-term2" as="xs:string">foo</xsl:param>
  <xsl:param name="replacement-term2" as="xs:string">foo2</xsl:param>

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="seg/date[following-sibling::node()[1][self::text()[starts-with(., '.')]]]">
      <xsl:copy>
          <xsl:value-of select=". || '.'"/>
      </xsl:copy>
  </xsl:template>

  <xsl:template match="seg/text()[starts-with(., '.') and preceding-sibling::node()[1][self::date]]">
      <xsl:value-of select="substring(., 2)"/>
  </xsl:template>

  <xsl:template match="seg/text()[matches(., '^\s*' || $search-term2 || '(\W|$)') and preceding-sibling::node()[1][self::date]]">
      <xsl:value-of select="replace(., '^(\s*)(' || $search-term2 || ')', '$1' || $replacement-term2)"/>
  </xsl:template>

</xsl:stylesheet>