2011-01-25 7 views
0

숨겨진 필드에 인접한 특정 버튼에서 가져온 값을 가져와야하는 숨겨진 필드를 어떻게 알 수 있습니까? 이 버튼은 또한 while 루프에 있기 때문에 버튼 목록과 숨겨진 필드가 생깁니다. 각 버튼에는 인접한 숨겨진 필드가 있습니다.PHP 내부에서 숨겨진 필드를 반복하면서 테이블 행에있는 루프

jquery ajax를 사용하여 DB의 테이블에 숨겨진 필드의 데이터를 삽입하고 싶지만 모든 버튼을 클릭하면 어느 것이 클릭되는지 알기 때문에 루프가 잘 작동하지만 문제는 원점에 돌아옵니다 숨겨진 필드를 통해 마지막 숨겨진 필드의 값을 가져옵니다. 클릭 한 버튼 바로 옆에있는 숨겨진 필드의 값을 얻으려면 어떻게해야합니까? 정말 도움을 주시면 감사하겠습니다. 고맙습니다.

JQuery와는

$(#list_tb input[type=submit]).each(function(){ 
$(this).click(function(){ 
$(#list_tb input[type=hidden]).each(function(){ 
var value=$(this).val(); 
alert(value); 
}); 
}); 
}); 

답변

0

jQuery(".but").click(function(){ 
    var hidVal = jQuery(this).closest("div.child").find("hid").val(); 
}); 
0

등이

<div id="parent"> 
    <div class="child"> 
     <span><input type="hidden" class="hid" value="1"></span> 
     <span><input type="button" class="but" value="submit"></span> 
    </div> 
    <div class="child"> 
     <span><input type="hidden" class="hid" value="3"></span> 
     <span><input type="button" class="but" value="submit"></span> 
    </div> 
</div> 

jQuery 코드처럼 HTML 난 그냥 Harish에 의해 주어진 HTML을 따기하고 말 .. .. 이런 식으로 할 수 있습니다 ..

<div id="parent"> 
<div class="child"> 
    <span><input type="hidden" class="hid" value="1"></span> 
    <span><input type="button" class="but" value="submit"></span> 
</div> 
<div class="child"> 
    <span><input type="hidden" class="hid" value="3"></span> 
    <span><input type="button" class="but" value="submit"></span> 
</div> 

및 JQuery와이 될 것입니다 ..

jQuery(".but").click(function(){ 
    var hidVal = jQuery(this).parents("div.child").find("hid").val(); 
}); 
0

고맙습니다 guyz이있다, 나는 그것의 긴 짧은, 그것을 해결하기 위해 가지고 있지만,이 코드를 필요로 누군가를 위해, 일 그것은

<form id="form1" name="form1" method="post" action="load_modules.php"> 
    <table width="500" id="orderlist_table"> 
    <tr> 
     <th width="78" style="font-size: 12px">type</th> 
     <th width="82" style="font-size: 12px">amount</th> 
     <th width="90" style="font-size: 12px">date</th> 
     <th colspan="5" style="font-size: 12px">invoice order</th> 
    </tr> 
    <?php 

     while($order_rows=mysql_fetch_assoc($orderSQL)) 
     { 
     ?> 
    <tr> 
     <td height="26" style="font-size: 12px"><?php echo $order_rows['Type']; ?></td> 
     <td style="font-size: 12px"><?php echo $order_rows['Total_amount']; ?></td> 
     <td style="font-size: 12px"><?php echo $order_rows['Date']; ?></td> 
     <td width="55" id="invoice_btn_td" style="font-size: 12px"> 
     <input type="submit" name="invoice_btn" id="hf<?php echo $order_rows['id'];?>" value="invoice"/> 
     </td> 
     <td width="30" id="userid_td" style="font-size: 12px"> 
     <input type="hidden" name="user_idhf" id="hf<?php echo $order_rows['id'];?>" value="<?php echo $order_rows['User_id']; ?>" /> 
     </td> 
     <td width="35" id="type_td" style="font-size: 12px" > 
     <input type="hidden" name="typehf" id="hf<?php echo $order_rows['id'];?>" value="<?php echo $order_rows['Type'];?>" /> 
     </td> 
     <td width="37" id="order_td" style="font-size: 12px"> 
     <input type="hidden" name="orderidhf" id="hf<?php echo $order_rows['id'];?>" value="<?php echo $order_rows['id'];?>" /> 
     </td> 
     <td width="57" id="amount_td" style="font-size: 12px"> 
     <input type="hidden" name="total_amounthf" id="hf<?php echo $order_rows['id'];?>" value="<?php echo $order_rows['Total_amount']?>" /> 
     </td> 
    </tr> 
    <?php 
     } 
     ?> 
    </table> 

jQuery를 간다 방법 :

$("#orderlist_table input[type=submit]").each(function(){ 
    $(this).click(function(){ 
     var btn_id=$(this).attr('id'); 
     var userid_value; 
     var type_value; 
     var orderid_value; 
     var totalamount_value; 
     $("#userid_td input[type=hidden]").each(function(){ 
       var userid_id=$(this).attr('id'); 
       if(userid_id==btn_id) 
       { 
        userid_value=$(this).attr('value'); 
       } 
     }); 
     $("#type_td input[type=hidden]").each(function(){ 
       var type_id=$(this).attr('id'); 
       if(type_id==btn_id) 
       { 
        type_value=$(this).attr('value'); 
       } 
     }); 
     $("#order_td input[type=hidden]").each(function(){ 
       var order_id=$(this).attr('id'); 
       if(order_id==btn_id) 
       { 
        orderid_value=$(this).attr('value'); 
       } 
     }); 
     $("#amount_td input[type=hidden]").each(function(){ 
       var amount_id=$(this).attr('id'); 
       if(amount_id==btn_id) 
       { 
        totalamount_value=$(this).attr('value'); 
       } 
     }); 
     //alert(userid+" "+type_value+" "+orderid_value+" "+totalamount_value); 
     $.post("php_files/add_invoice.php",{user_idhf:userid_value, 
     typehf:type_value, 
     orderidhf:orderid_value, 
     total_amounthf:totalamount_value}, 
     function(data) 
      { 
       if(data.success) 
       { 
        alert(data.success); 
       } 
       if(!data.success) 
       { 
        alert(!data.success); 
       } 
      },'json'); 
     return false; 
    }); 


}); 

버튼의 끝에 숨겨진 필드와 동일한 이름을 지정하면 마지막에 카운터 번호가 표시되어 클릭 한 버튼의 이름을 숨겨진 필드와 동일하게합니다. 동일하면 동일한 행에 있거나 오히려 서로 인접 해있다. 그게 전부 야.

고관절 남자

관련 문제