2017-07-05 37 views
-1

我使用切換顯示/隱藏兩個元素。 我在切換顯示中顯示一個帶有buton鏈接的塊。 當用戶點擊按鈕鏈接時,我需要輸入一個例外。Jquery .not()不工作

我的功能與.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> 
+2

發佈相關的HTML。 –

+0

所以你想,但是我很長 – kwiz

+1

在你的問題中發佈相關的** HTML,而不是在答案中。在你發佈的代碼中,只有一個元素具有'item'類,另一個元素具有'.btn-cart'類。你知道jQuery的「不」嗎? – PeterMader

回答

1

.not()方法是用來 「濾除」 從集合某些元素。

通過jQuery('.item')收集的收集沒有還具有類btn-cart ...

這就是爲什麼它看起來像沒有工作的任何元素。

+0

嗡嗡聲,.item包含一個。 btn-cart – kwiz

+0

「包含」是不一樣的也有類。 –