我制作了一个动态表单,但是当我得到 json 结果时,它总是将结果传递给第一行到第一行我想将选定的结果传递给选定的行我的动态行如下所示我制作了一个动态表单但是当我得到 json 结果时它总是将结果传递给第一行我想将选定的结果传递给选定的行我的动态行像下面
这是我的ajax代码:
$(".items").on('change',function() {
var that = $(this);
var url = "http://localhost/QuickBacklog/web/app_dev.php/invoices/invoiceitem";
$.ajax({
type: "POST",
url: url,
data:{'invoiceitem' : that.find('option:selected').val()},
}).done(function( result ) {
var description=(result.description);
var unitprice=(result.unitprice);
var quantity=(result.quantity);
document.getElementById("description").innerHTML = description;
$("#unitprice").val(+unitprice);
$("#quantity").val(+quantity);
});
});
我的 json 结果正确但是当我传递结果时它只将结果传递给 #description,#unitprice,#quantity 而不是 #description2,#unitprice2,#quantity2
这是我的html代码:
<select id="items" class="items" style="width:127px; float:left;" name="items">
<option value="1">Clothes</option>
<option value="2">Office Stationery</option>
<option value="3">Furniture</option>
</select>
<textarea id="description" class="description" style="float:left; display: block; height: 30px; width:209px; border-radius:0px; margin: -1px 1px 0;" name="description"> </textarea>
<input id="unitprice" class="unitprice" type="text" style="float:left; display: block; height: 30px; width:106px; border-radius:0px; margin: -1px -1px 0;" name="unitprice">
<input id="quantity" class="quantity" type="text" style="float:left; display: block; height: 30px; width:64px; border-radius:0px; margin: -1px 1px 0;" name="quantity">
<select id="firsttax" style=" float:left; display: block; height: 31px; width:106px; border-radius:0px; margin: -2px -1px 0;" name="firsttax">
<select id="secondtax" style="float:left; display: block; height: 31px; width:107px; border-radius:0px; margin: -2px 0px 0;" name="secondtax">
和
<select id="items2" class="items" style="width:127px; float:left;" name="items2">
<option value="1">Clothes</option>
<option value="2">Office Stationery</option>
<option value="3">Furniture</option>
</select>
<textarea id="description2" class="description" style="float:left; display: block; height: 30px; width:209px; border-radius:0px; margin: -1px 1px 0;" name="description2"> </textarea>
<input id="unitprice2" class="unitprice" type="text" style="float:left; display: block; height: 30px; width:106px; border-radius:0px; margin: -1px -1px 0;" name="unitprice2">
<input id="quantity2" class="quantity" type="text" style="float:left; display: block; height: 30px; width:64px; border-radius:0px; margin: -1px 1px 0;" name="quantity2">
<select id="firsttax2" style=" float:left; display: block; height: 31px; width:106px; border-radius:0px; margin: -2px -1px 0;" name="firsttax2">
<select id="secondtax2" style="float:left; display: block; height: 31px; width:107px; border-radius:0px; margin: -2px 0px 0;" name="secondtax2">