我试图从自动完成中获取值并将它们绑定到文本框,它在动态文本框上工作得很好但不在静态文本框上工作。我分享到目前为止我所做的事情
JQUERY:
function bindData(auto, MFG, DC, PKG, BP) {
var errormsg = "";
var amount = $(auto).val();
$.ajax({
type: "GET",
url: '/Admin/Ticket/GetPart',
data: { 'term': amount },
dataType: "json",
success: function (data) {
if (data != null) {
if (data.length > 0) {
$(MFG).val(data[1].Manufacturer);
$(DC).val(data[0].DateCode);
$(PKG).val(data[0].PackageCase);
$(BP).val(data[0].Price);
}
else {
$(MFG).val('');
$(DC).val('');
$(PKG).val('');
$(BP).val('');
}
}
},
error: function (jqXHR, exception) {
$('#error').html(jqXHR)
}
});
};
$(function () {
window.count = 0;
$("#del").hide();
$("a[id^='add']").live("click", null, function () {
var l = $("#maintable > tbody > tr").length;
if (l > 0) {
$("#del").fadeIn('300');
}
window.count++;
var PartNumber = "PartNumber" + window.count;
var MFG = "Manufacturer" + window.count;
var DC = "DateCode" + window.count;
var PKG = "Package" + window.count;
var Quantity = "Quantity" + window.count;
var CustomQuantity = "CustomQuantity" + window.count;
var BP = "BuyingPrice" + window.count;
var BPUSD = "bpusd" + window.count;
var AMTUSD = "amtusd" + window.count;
var LTDAYS = "LTDays" + window.count;
var Description = "Description" + window.count;
var Note = "Note" + window.count;
var btnAddID = "add" + window.count;
var btnDelID = "del" + window.count;
var table = $("#maintable");
var tr = $("<tr></tr>")
.append($("<td><input id='" + PartNumber + "' type='text' style='width:130px;' /></td>"
+ "<td><input id='" + MFG + "' type='text' /></td>"
+ "<td><input id='" + DC + "' type='text' /></td>"
+ "<td><input id='" + PKG + "' type='text' /></td>"
+ "<td><input id='" + Quantity + "' class='text-box single-line' data-val='true' data-val-number='The field Quantity must be a number.' data-val-required='The Quantity field is required.' name='Quantity' style='width:35px;' type='number' value='' /></td>"
+ "<td><input id='" + CustomQuantity + "' class='text-box single-line' name='CustomQuantity' style='width:35px;' type='text' value='' /></td>"
+ "<td><input id='" + BP + "' type='text' /></td>"
+ "<td><input id='" + BPUSD + "' name='ConvertedBP' readonly='readonly' type='text' value='' /></td>"
+ "<td><input id='" + AMTUSD + "' name='ConvertedAmount' readonly='readonly' type='text' value='' /></td>"
+ "<td><input id='" + LTDAYS + "' name='LTDays' type='text' value='' /></td>"
+ "<td><select class='drop' id='" + Description + "' name='Description'>" +
"<option>Original ROHS</option>"
+ "<option>ROHS Compliance</option>"
+ "</select></td>"
+ "<td><textarea class='txtarea text-box multi-line' id='" + Note + "' name='Note' placeholder='Any Note With Ticket'></textarea></td>"
));
tr.appendTo(table);
});
$("#del").click(function () {
var l = $("#maintable > tbody > tr").length;
if (l == 2) {
$("#del").fadeOut('300');
}
$('tr:last').remove();
});
$("input:text[id^='PartNumber']").live("keyup", null, function () {
bindData("input:text[id^='PartNumber" + window.count + "'" + "]",
"input:text[id^='Manufacturer" + window.count + "'" + "]",
"input:text[id^='DateCode" + window.count + "'" + "]",
"input:text[id^='Package" + window.count + "'" + "]",
"input:text[id^='BuyingPrice" + window.count + "'" + "]"
);
$(this).autocomplete(
{
source: function (request, response) {
$.ajax({
url: '/Admin/Ticket/GetPart',
type: "GET",
dataType: "json",
data: { term: request.term },
success: function (data) {
if (data != null) {
if (data.length > 0) {
response($.map(data, function (item) {
return { label: item.PartNumber, value: item.PartNumber };
}))
}
else {
response([{ label: 'No results found.' }]);
}
}
}
})
},
});
$(this).autocomplete();
});
});
HTML:
<table id="maintable">
<thead>
<tr>
<th>
Part No
</th>
<th>
MFG
</th>
<th>
DC
</th>
<th>
PKG
</th>
<th>
QTY. Need
</th>
<th>
QTY. Offer
</th>
<th>
BP
</th>
<th>
BP(USD)
</th>
<th>
AMT (USD)
</th>
<th>
LT Days
</th>
<th>
Desc
</th>
<th>
Note
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" name="abcd" id="PartNumber" style="width:130px;" />
</td>
<td>
<input class="text-box single-line" id="Manufacturer" name="Manufacturer" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Manufacturer" data-valmsg-replace="true"></span>
</td>
<td>
<input class="text-box single-line" id="DateCode" name="DateCode" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="DateCode" data-valmsg-replace="true"></span>
</td>
<td>
<input class="text-box single-line" id="Package" name="Package" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Package" data-valmsg-replace="true"></span>
</td>
<td>
<input class="text-box single-line" data-val="true" data-val-number="The field Quantity must be a number." data-val-required="The Quantity field is required." id="Quantity" name="Quantity" style="width:35px;" type="number" value="" />
<span class="field-validation-valid" data-valmsg-for="Quantity" data-valmsg-replace="true"></span>
</td>
<td>
<input class="text-box single-line" id="CustomQuantity" name="CustomQuantity" style="width:35px;" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="CustomQuantity" data-valmsg-replace="true"></span>
</td>
<td>
<input class="buyingprice text-box single-line" id="buyingprice" name="BuyingPrice" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="BuyingPrice" data-valmsg-replace="true"></span>
</td>
<td>
<input id="bpusd" name="ConvertedBP" readonly="readonly" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="ConvertedBP" data-valmsg-replace="true"></span>
</td>
<td>
<input id="amtusd" name="ConvertedAmount" readonly="readonly" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="ConvertedAmount" data-valmsg-replace="true"></span>
<span id="error" class="error"></span>
</td>
<td>
<input id="LTDays" name="LTDays" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="LTDays" data-valmsg-replace="true"></span>
</td>
<td>
<select class="drop" id="Description" name="Description"><option>Original ROHS</option>
<option>ROHS Compliance</option>
</select>
<span class="field-validation-valid" data-valmsg-for="Description" data-valmsg-replace="true"></span>
</td>
<td>
<textarea class="txtarea text-box multi-line" id="Note" name="Note" placeholder="Any Note With Ticket">
</textarea>
<span class="field-validation-valid" data-valmsg-for="Note" data-valmsg-replace="true"></span>
</td>
</tr>
</tbody>
</table>
请指导我