2017-02-20 67 views
-1

我将数据追加到tbody,这是通过ajax请求获得的。在后端我打印这样如何获得动态添加的​​中的下一个输入的值

echo "<tr> 
     <td><input type='text' name='sl_p_codes[]' id='p_code' value='{$data['p_code']}' ></td> 
     <td><input type='text' name='sl_products[]' id='qty' value='{$data['p_name']}' ></td> 
     <td><input type='text' id='product_qty' name='sl_p_qty[]' id='qt' value='01' size='2'></td> 
     <td><input type='hidden' name='sl_unit_cost[]' id='product_unit_price'></td> 
     <td><input type='text' id='product_total_cost' readonly name='sl_price[]' id='qty' value='{$data['p_price']}' ></td> 
     <td class='center'><a href='#' onclick='delrow(this);' class='btn btn-danger'>X</a></td> 
    </tr>"; 

如果我改变id='product_qty'(输入字段)id='product_total_cost'(输入字段)的值应与id='product_unit_price'

+2

这听起来像是你知道你需要什么,我建议你开始正在做。 StackOverflow不是您编写规范的网站,而是其他人为您编写代码。显示你迄今为止所写的内容,并准确描述你卡在哪里。 – Tomalak

+0

我没有得到输出到有ID的输入字段product_total_cost –

+0

请再次阅读我的评论。注意最后一句话。 – Tomalak

回答

1

值来更新你的意思是这样的数据:

$("#product_qty").on("change", function() { 
 
    $(this).closest("tr").find("#product_total_cost").val(
 
    (parseFloat($(this).closest("tr").find("#product_unit_price").val()) * parseInt($(this).val())).toFixed(2) 
 
); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
    <tr> 
 
    <td><input type='text' name='sl_p_codes[]' id='p_code' value='ABC011'></td> 
 
    <td><input type='text' name='sl_products[]' id='qty' value='01'></td> 
 
    <td><input type='number' id='product_qty' name='sl_p_qty[]' id='qt' value='01' size='2'></td> 
 
    <td><input type='hidden' name='sl_unit_cost[]' id='product_unit_price' value="1.00"></td> 
 
    <td><input type='text' id='product_total_cost' readonly name='sl_price[]' id='qty' value='1.00'></td> 
 
    <td class='center'><a href='#' onclick='delrow(this);' class='btn btn-danger'>X</a></td> 
 
    </tr> 
 
</table>

+0

如果我改变第二个输入字段,它应该是这样的第四个输入值=第二个输入值X第三个输入值。 –

+0

您可以修改它以满足您的需求。 –

相关问题