使用.not()并不能正常工作-JQuery

问题描述 投票:-1回答:1

我正在使用切换显示/隐藏两个元素。我在切换显示中显示带有按钮链接的块。当用户单击按钮链接时,我需要为切换设置例外。

我的.not功能无法正常工作。我尝试使用下面编写的代码。您能指出我出问题的地方吗?

  // On cache le block d'ajout au panier et l'image dans le block texte
  jQuery('.panier_block').hide();
  jQuery('.img_toggle').hide();

 // les cachés s'affichent et les affichés se cachent avec toggle.
  jQuery('.item').not('.btn-cart').click( function() {
      jQuery(this).find('.panier_block').toggle(275);
      jQuery(this).find('.product-image').toggle(275);
      jQuery(this).find('.product-image-subtext').toggle(275);
      jQuery(this).find('.product_info_sub_block_text').toggle(275);

  })

我的HTML:

<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
      <!-- <a href="#" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image" id="product-switch-<?php echo $z; ?>"> -->
        <div class="product-image" id="product-switch-<?php echo $z; ?>">
            <?php $_imgSize = 398; ?>
            <img id="product-collection-image-<?php echo $_product->getId(); ?>"
                 src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($_imgSize); ?>"
                 alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
        </div>
      <!-- </a> -->

 <!-- Panier-->
  <div class="product_info_block panier_block">
    <div class="product_info_sub_block">

        <div class="product-info">
            <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
            <?php
            // Provides extra blocks on which to hang some features for products in the list
            // Features providing UI elements targeting this block will display directly below the product name
            if ($this->getChild('name.after')) {
                $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
                foreach ($_nameAfterChildren as $_nameAfterChildName) {
                    $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
                    $_nameAfterChild->setProduct($_product);
                    echo $_nameAfterChild->toHtml();
                }
            }
            ?>
            <!-- Affiche le poids-->
            <div class="block_weight_cat">

          <span class="weight_cat">
            <?php $_product = Mage::getModel('catalog/product')->load($_product->getId());
              $_weight = $this->htmlEscape($_product->getWeight());
                if ($_weight < 1)
                  $_weightstr = number_format($_weight*1000) . " mll";
                else
                  $_weightstr = number_format($_weight) . " cl";
              echo $_weightstr;
              ?>
          </span>
        </div>

            <?php echo $this->getPriceHtml($_product, true) ?>
            <?php if($_product->getRatingSummary()): ?>
            <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
            <?php endif; ?>


            <div class="actions">
                <?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
                    <button type="button" title="<?php echo $this->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

                <?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
                    <a title="<?php echo $this->quoteEscape($this->__('View Details')) ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a>
                <?php else: ?>
                    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                <?php endif; ?>
                <ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                        <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                    <?php endif; ?>
                </ul>
            </div>
            <a class="discover"href="<?php echo $_product->getProductUrl() ?>" title="">En savoir plus</a> <span class="iconm-arrow_2">  </span>

        </div>
      </div>    <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
  <!-- <a href="#" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image" id="product-switch-<?php echo $z; ?>"> -->
  <div class="product-image" id="product-switch-<?php echo $z; ?>">
    <?php $_imgSize = 398; ?>
    <img id="product-collection-image-<?php echo $_product->getId(); ?>"
         src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($_imgSize); ?>"
         alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
  </div>
  <!-- </a> -->

  <!-- Panier-->
  <div class="product_info_block panier_block">
    <div class="product_info_sub_block">

      <div class="product-info">
        <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
        <?php
// Provides extra blocks on which to hang some features for products in the list
// Features providing UI elements targeting this block will display directly below the product name
if ($this->getChild('name.after')) {
$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
foreach ($_nameAfterChildren as $_nameAfterChildName) {
$_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
$_nameAfterChild->setProduct($_product);
echo $_nameAfterChild->toHtml();
}
}
?>
        <!-- Affiche le poids-->
        <div class="block_weight_cat">

          <span class="weight_cat">
            <?php $_product = Mage::getModel('catalog/product')->load($_product->getId());
$_weight = $this->htmlEscape($_product->getWeight());
if ($_weight < 1)
$_weightstr = number_format($_weight*1000) . " mll";
else
$_weightstr = number_format($_weight) . " cl";
echo $_weightstr;
?>
          </span>
        </div>

        <?php echo $this->getPriceHtml($_product, true) ?>
        <?php if($_product->getRatingSummary()): ?>
        <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
        <?php endif; ?>


        <div class="actions">
          <?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
          <button type="button" title="<?php echo $this->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

          <?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
          <a title="<?php echo $this->quoteEscape($this->__('View Details')) ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a>
          <?php else: ?>
          <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
          <?php endif; ?>
          <ul class="add-to-links">
            <?php if ($this->helper('wishlist')->isAllow()) : ?>
            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
            <?php endif; ?>
            <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
            <?php endif; ?>
          </ul>
        </div>
        <a class="discover"href="<?php echo $_product->getProductUrl() ?>" title="">En savoir plus</a> <span class="iconm-arrow_2">  </span>

      </div>
    </div>
  </div>


  <!-- block de texte-->
  <div class="product_info_block bg_cat">

    <div class="product-image-subtext img_toggle" id="product-switch-<?php echo $z; ?>" >
      <?php $_imgSize = 398; ?>
      <img id="product-collection-image-<?php echo $_product->getId(); ?>"
           src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($_imgSize); ?>"
           alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
    </div>

    <div class="product_info_sub_block product_info_sub_block_text">

      <div class="product-info">
        <h2 class="product-name product-name-cat"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
        <?php
// Provides extra blocks on which to hang some features for products in the list
// Features providing UI elements targeting this block will display directly below the product name
if ($this->getChild('name.after')) {
$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
foreach ($_nameAfterChildren as $_nameAfterChildName) {
$_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
$_nameAfterChild->setProduct($_product);
echo $_nameAfterChild->toHtml();
}
}
?>
        <?php if($_product->getRatingSummary()): ?>
        <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
        <?php endif; ?>
        <div class="text_describe_cat">
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
            . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
            in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        </div>

      </div>
    </div>
  </div>


</li>
      </div>


      <!-- block de texte-->
      <div class="product_info_block bg_cat">

        <div class="product-image-subtext img_toggle" id="product-switch-<?php echo $z; ?>" >
            <?php $_imgSize = 398; ?>
            <img id="product-collection-image-<?php echo $_product->getId(); ?>"
                 src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($_imgSize); ?>"
                 alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
        </div>

        <div class="product_info_sub_block product_info_sub_block_text">

            <div class="product-info">
                <h2 class="product-name product-name-cat"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
                <?php
                // Provides extra blocks on which to hang some features for products in the list
                // Features providing UI elements targeting this block will display directly below the product name
                if ($this->getChild('name.after')) {
                    $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
                    foreach ($_nameAfterChildren as $_nameAfterChildName) {
                        $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
                        $_nameAfterChild->setProduct($_product);
                        echo $_nameAfterChild->toHtml();
                    }
                }
                ?>
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <div class="text_describe_cat">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
        . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
        in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                </div>

            </div>
          </div>
          </div>


    </li>
javascript jquery
1个回答
1
投票

.not()方法用于“过滤”集合中的某些元素。

.not()收集的集合没有任何元素也具有类jQuery('.item') ...

这就是为什么它看起来不起作用的原因。

© www.soinside.com 2019 - 2024. All rights reserved.