English 中文(简体)
仅替换一个要素,而不是全部
原标题:Replace only one element and not all

在奥基斯,我曾尝试过我,然后在这里站出来,但此时我已走过墙。

我有一份产品清单,每个产品都有Add To Cartutton/image,我希望以形象的项目。

我面临的问题是,当我取而代之时,所有图像都被更换。 现在,你可以告诉我,我是多么新。

This is my jQuery:

//Replace the  Add To Cart  button
 $( .add-to-cart-btn ).click(function(){
   $( .add-to-cart-btn ).replaceWith( <img src="images/button-added-to-cart.png" alt="Item added to Cart"> );
 return false;
 });

这里是我的超文本:

<a href="#" class="add-to-cart-btn"><img src="images/button-add-to-cart.png" alt="Add to Cart"></a>

As you can see, I m replacing the entire ahref element because when the item is added, I don t want that button to be clickable again.

任何想法,如何仅仅把任何特定的Add To Cartutton/image取而代之,而不是所有纽州?

感谢你给我的任何帮助和指导。

最佳回答

你只想取代你选定的项目(AKA,被点击的项目),这样就不再选择,而是使用被点击的物体。

//Replace the  Add To Cart  button
 $( .add-to-cart-btn ).click(function(){
   $(this).replaceWith( <img src="images/button-added-to-cart.png" alt="Add to Cart"> );
 return false;
 });
问题回答

我认为,这样做的更有效办法是:

$( .add-to-cart-btn ).click(function() {
    this.src =  images/button-added-to-cart.png ;
    this.alt =  Item added to Cart ;
    return false;
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签