识别图像点击次数

时间:2016-03-28 09:40:03

标签: javascript html

我有以下代码,其中我有图像,我不喜欢它们。我想确定哪个图像被点击了不喜欢?我该怎么做?

<div class="product_title"><a href="details.html">Levi's Men's Cotton T-Shirt</a></div>
      <div class="product_img"><a href="details.html"><img src="images/T1.jpg" alt="" border="0" id="T1"/></a></div>
       <div class="product_img"><img src="images/dislike.jpeg" onclick="getId();" align="right" id="d1"/></a></div>
      <div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
    </div>
    <div class="bottom_prod_box"></div>
    <div class="prod_details_tab"> <a href="#" title="header=[Add to cart] body=[&nbsp;] fade=[on]"><img src="images/cart.gif" alt="" border="0" class="left_bt" /></a> <a href="#" title="header=[Specials] body=[&nbsp;] fade=[on]"><img src="images/favs.gif" alt="" border="0" class="left_bt" /></a> <a href="#" title="header=[Gifts] body=[&nbsp;] fade=[on]"><img src="images/favorites.gif" alt="" border="0" class="left_bt" /></a> <a href="details.html" class="prod_details">details</a> </div>
  </div>
  <div class="prod_box">
    <div class="top_prod_box"></div>
    <div class="center_prod_box">
      <div class="product_title"><a href="details.html">UB Stylish T-shirt</a></div>
      <div class="product_img"><a href="details.html"><img src="images/T2.jpg" alt="" border="0" id="T2"/></a></div>
       <div class="product_img"><img src="images/dislike.jpeg" alt="" border="0" align="right" id="d2"/></a></div>
      <div class="prod_price"><span class="price">270$</span></div>
    </div>
    <div class="bottom_prod_box"></div>
    <div class="prod_details_tab"> <a href="#" title="header=[Add to cart] body=[&nbsp;] fade=[on]"><img src="images/cart.gif" alt="" border="0" class="left_bt" /></a> <a href="#" title="header=[Specials] body=[&nbsp;] fade=[on]"><img src="images/favs.gif" alt="" border="0" class="left_bt" /></a> <a href="#" title="header=[Gifts] body=[&nbsp;] fade=[on]"><img src="images/favorites.gif" alt="" border="0" class="left_bt" /></a> <a href="details.html" class="prod_details">details</a> </div>
  </div>
  <div class="prod_box">
    <div class="top_prod_box"></div>
    <div class="center_prod_box">
      <div class="product_title"><a href="details.html">Jacob n John T-Shirt</a></div>
      <div class="product_img"><a href="details.html"><img src="images/T3.jpg" alt="" border="0" id="T3" /></a></div>
       <div class="product_img"><img src="images/dislike.jpeg" alt="" border="0" align="right" id="d3"/></a></div>
      <div class="prod_price"><span class="reduce">350$</span> <span class="price">270$</span></div>
    </div>

1 个答案:

答案 0 :(得分:0)

您可以将不喜欢图片按钮与onclick事件绑定。找到元素的id,然后使用id查找产品ID。

由于您的标记是结构化的,因此元素的ID为d i,因此产品的对应ID为t i