我想将 jquery 效果“flash”应用于“simpleCart_shelfItem”,即 html 元素“item_add”的父级。这是为了表明用户已将商品添加到购物车。我通过引用父级来做到这一点,因为有很多“simpleCart_shelfItem”实例,我希望效果只发生在被点击的那个上。我一直在阅读this
我收集的内容,我不能将onClick
事件内联,因为this
它将是全局的,而不是引用函数中的元素。这就是我所拥有的:
Javascript
$(".item_add").onclick = highlight;
function highlight(){
$(".item_add").parent().effect("highlight", {}, 750);
};
HTML
<div class="simpleCart_shelfItem">
<div class="image"><img src="css/graphics/jpeg/saw.jpg" alt="Hacksaw" height="75" width="75" /></div>
<h2 class="item_name">Hacksaw</h2>
<span class="item"><img src="css/graphics/jpeg/cart.jpg" alt="Shopping Cart" height="20" width="19" />
Items in Cart: <b class="simpleCart_quantity"></b></span>
<div class="description"><p>Quality metal hacksaw and 24 tooth blade.</p><p class="p_height">Your going to need some way of cutting that pipe. Good for the toolbox.</p></div>
<a class="add_products" href="cart.html">Go to Cart</a>
<a class="add_products" href="products.html" title="Add Items">Add More Items</a>
<span class="gst">(Inc. GST)</span>
<span class="item_price">$24.95</span>
<input class="item_quantity" value="1" type="text">
**<a href="javascript:;" class="item_add" onclick="highlight();">Add</a>**
</div><!--end of simpleCart_shelfItem-->