2010-02-05 79 views
4

我试图将这些形式阿贾克斯 (例子)jQuery的选择输入[类型=图像]兄弟姐妹

<table> 
<tr> 
      <td>Prov</td><td>Cod</td><td>Nombre</td><td>Precio</td><td>Stock1</td><td></td><td></td> 
     </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011135</td> 
        <td class="name" id="artID13899">Eje del. m505 y4ch98040 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;69.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005834" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13899" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011137</td> 
        <td class="name" id="artID13900">Eje del. m565 y4c698010 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;260.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005835" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13900" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011143</td> 
        <td class="name" id="artID13905">Eje del. m775 y26k98030 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;290.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005837" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13905" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011153</td> 
        <td class="name" id="artID13910">Eje del. r500 y4bg98030 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;73.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005841" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13910" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 

       <tr class="o d"> 
        <td class="provName">Karabitian</td> 

        <td class="cod d">494011157</td> 
        <td class="name" id="artID13914">Eje del. r560 y4c498010 comp. s/cierre Shimano</td> 
        <td class="alignright">$&nbsp;137.00</td> 
        <td class="center">-</td> 
        <td class="add"> 
       <nobr> 

        <form name="formularioAgregaItem" action="script.php" method="POST" autocomplete="off" class="add"> 
         <fieldset> 
          <input name="function" value="cartAddByBarcode" type="hidden"> 
          <input name="barcode" value="KAR005845" type="hidden"> 
          <input name="orderID" value="23333" type="hidden"> 
          <input name="qty" id="qty13914" size="2" maxlength="3" class="i" value="15" type="text"> 
          <input src="add_16x16.gif" alt="agregar a la orden" type="image"> 
         </fieldset> 
        </form> 

       </nobr> 
       </td> 
       </tr> 
</table> 

但我无法弄清楚如何从同一行我点击获得的输入

$('input[type=image]').click(function(){ 
    // insert voodoo go get inputs here 
    // ajax call 
    return false; 
}); 

我不能这样做$(输入[名称= “条形码”]) 任何想法?

回答

12

你需要做某事,如:

$('input[type=image]').click(function(){ 
    var image = $(this); 
    var parent = image.parent(); // this will be the fieldset, could also do .closest('fieldset)', if the fieldset is not the immediate parent 
    var neededInput = $('input[name=barcode]', parent); 
    // do something with it 
    return false; 
}); 

或使用siblings() - 方法

$('input[type=image]').click(function (event){ 
    event.preventDefault(); 
    var $image = $(this); 
    var $neededInput = $image.siblings('input[name=barcode]'); 
    // do something with it 
}); 
+0

工作就像一个魅力,谢谢! – 2010-02-05 10:52:23

+0

不客气! – 2010-02-05 15:46:07

1

你的点击函数中,this将是您单击的图像的参考。所以,你可以做

$(this).siblings() 

$(this).closest('fieldset').find(...); 
+0

可能我误解了你,但是这个我只有其他的输入类型图像... – 2010-02-05 10:53:43