Javascript 在mutli div内选择多输入
我正在为零售产品构建CRM应用程序 在Receipt表单中,可以包含来自同一类别的多个产品 下面是一个类别的示例Javascript 在mutli div内选择多输入,javascript,jquery,html,Javascript,Jquery,Html,我正在为零售产品构建CRM应用程序 在Receipt表单中,可以包含来自同一类别的多个产品 下面是一个类别的示例 <div id="frame_item"> <label>شنبر</label> <input type="text" id="frame_code" name="frame_code" onfocus="autoSelectFrame("frame_code")"> <label>بي
<div id="frame_item">
<label>شنبر</label>
<input type="text" id="frame_code" name="frame_code" onfocus="autoSelectFrame("frame_code")">
<label>بيانات الشنبر</label>
<input type="text" id="frame_details" name="frame_details" disabled>
<label>سعر الشنبر</label>
<input type="text" id="frame_sell_price" name="frame_sell_price" value="5" class="frame_sell_price" disabled>
<label>الكمية</label>
<input type="text" id="frame_quantity" name="frame_quantity" class="frame_quantity" value="1" onchange="updateItemPrice("frame");">
<input type="text" id="frame_total_price" name="frame_total_price" class="frame_total_price" value="" disabled>
问题是,它使用相同的值更新所有内容。问题在于,
$(“.frame\u quantity”)
和$(“.frame\u sell\u price”)
从文档根目录中搜索,并找到所有匹配的元素。然后val()
检索第一个匹配元素的值
您需要的是:
var finalPrice = 0;
$(".frame_item").each(function(i){
var item = $(this);
var quantity = item.find(".frame_quantity").val();
var price = item.find(".frame_sell_price").val();
finalPrice = parseInt(quantity) * parseInt(price);
item.find(".frame_total_price").val(finalPrice);
alert(finalPrice);
});
这将触发搜索当前项目内的数量和价格
同样从jQuery选择器中,我假设
实际上是
有多个frame\u项?顺便说一句,html说frame_item是id,但js代码假设frame_item是class。然而,正如您所说的,您的代码以某种方式工作。
var finalPrice = 0;
$(".frame_item").each(function(i){
var item = $(this);
var quantity = item.find(".frame_quantity").val();
var price = item.find(".frame_sell_price").val();
finalPrice = parseInt(quantity) * parseInt(price);
item.find(".frame_total_price").val(finalPrice);
alert(finalPrice);
});