2010-02-05 4 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; 
}); 

나는 $ 같은 (입력 [이름 = "바코드"]) 어떤 아이디어를 할 수없는 이유는 무엇입니까?

$('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() -method

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

답변

12

당신은 STH처럼 할 필요가있다. 그래서 당신은, 덕분에 마법처럼 일했다

$(this).siblings() 

또는

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

할 수 있습니다! –

+0

당신을 환영합니다! –

1

를 사용하여, this 당신이 클릭 한 이미지에 참조가 될 것입니다 :

+0

아마 당신을 오해 했겠지만, 이것으로 나는 다른 사람들이 입력 한 이미지만을 입력 받았다. –

관련 문제