Javascript 选择多个累加数据,如何清理?
帮助,我有一个表单,当我选择一个客户时,它会自动填充数据,其中包括他们的地址,这些地址会加载到一个select multiple中。问题是:当我选择另一个客户时,表单没有完全清理,或者是将前一个客户的地址作为当前客户的地址累加在select multiple中。选择其他客户时,是否可以自动清理整个表单或至少选择多个表单?谢谢Javascript 选择多个累加数据,如何清理?,javascript,jquery,json,ajax,forms,Javascript,Jquery,Json,Ajax,Forms,帮助,我有一个表单,当我选择一个客户时,它会自动填充数据,其中包括他们的地址,这些地址会加载到一个select multiple中。问题是:当我选择另一个客户时,表单没有完全清理,或者是将前一个客户的地址作为当前客户的地址累加在select multiple中。选择其他客户时,是否可以自动清理整个表单或至少选择多个表单?谢谢 $('input[name=\'customer\']').catcomplete({ minLength: 0, delay: 100, source: functio
$('input[name=\'customer\']').catcomplete({
minLength: 0, delay: 100,
source: function(request, response) {
$.ajax({
url: 'index.php?route=sale/customer/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
category: item['customer_group'],
label: item['name'],
value: item['customer_id'],
customer_group_id: item['customer_group_id'],
firstname: item['firstname'],
lastname: item['lastname'],
rut_cliente_id: item['rut_cliente_id'],
email: item['email'],
telephone: item['telephone'],
fax: item['fax'],
banca: item['banca'],
company: item['company'],
iban: item['iban'],
address: item['address']
}
}));
}
});
},
select:function(event,ui){
event.preventDefault()
$('input[name=\'customer\']').val(ui.item.label);
$('input[name=\'customer_id\']').val(ui.item.value);
$('input[name=\'firstname\']').val(ui.item.firstname);
$('input[name=\'lastname\']').val(ui.item.lastname);
$('input[name=\'rut_cliente_id\']').val(ui.item.rut_cliente_id);
$('input[name=\'email\']').val(ui.item.email);
$('input[name=\'telephone\']').val(ui.item.telephone);
$('input[name=\'banca\']').val(ui.item.banca);
$('input[name=\'iban\']').val(ui.item.iban);
$('input[name=\'company\']').val(ui.item.company);
$('input[name=\'fax\']').val(ui.item.fax);
for(i in ui.item.address){
html+='<option value="' + ui.item.address[i]['address_id']+'">'+ui.item.address[i]['firstname']+' ' + ui.item.address[i]['lastname']+', ' + ui.item.address[i]['address_1']+', ' + ui.item.address[i]['city']+', ' + ui.item.address[i]['country']+'</option>';
}
$('select[name=\'shipping_address\']').html(html);
$('select[name=\'payment_address\']').html(html);
$('select[id=\'customer_group_id\']').removeAttr('disabled').val(ui.item['customer_group_id']).change().attr('disabled',true);
return false;
}});
$('input[name=\'customer\']')。catcomplete({
最小长度:0,延迟:100,
来源:功能(请求、响应){
$.ajax({
url:'index.php?route=sale/customer/autocomplete&token=&filter_name='+encodeURIComponent(request.term),
数据类型:“json”,
成功:函数(json){
响应($.map(json,函数(项){
返回{
类别:项目[“客户组”],
标签:项目['name'],
值:项目['customer_id'],
客户组标识:项目['customer\u group\u id'],
firstname:item['firstname'],
lastname:item['lastname'],
rut_客户id:项目['rut_客户id'],
电子邮件:项目['email'],
电话:项目[“电话”],
传真:项目[‘传真’],
银行:项目[‘银行’],
公司:项目[“公司”],
iban:项目['iban'],
地址:项目[“地址”]
}
}));
}
});
},
选择:功能(事件、用户界面){
event.preventDefault()
$('input[name=\'customer\']').val(ui.item.label);
$('input[name=\'customer\u id\']').val(ui.item.value);
$('input[name=\'firstname\']').val(ui.item.firstname);
$('input[name=\'lastname\']').val(ui.item.lastname);
$('input[name=\'rut\u cliente\u id\').val(ui.item.rut\u cliente\u id);
$('input[name=\'email\']').val(ui.item.email);
$('input[name=\'telephone\']').val(ui.item.telephone);
$('input[name=\'banca\']').val(ui.item.banca);
$('input[name=\'iban\']').val(ui.item.iban);
$('input[name=\'company\']').val(ui.item.company);
$('input[name=\'fax\']').val(ui.item.fax);
对于(ui.item.address中的i){
html++''+ui.item.address[i]['firstname']+'+ui.item.address[i]['lastname']+','+ui.item.address[i]['address_1']+','+ui.item.address[i]['city']+','+ui.item.address[i]['country']+';
}
$('select[name=\'shipping\u address\']')。html(html);
$('select[name=\'payment\u address\']')。html(html);
$('select[id=\'customer\u group\u id\']').removeAttr('disabled').val(ui.item['customer\u group\u id']).change().attr('disabled',true);
返回false;
}});
在设置新值之前使用此代码
$("input").each(function(){
$(this).val("");
});
$('select[name=\'shipping_address\']').html("");
$('select[name=\'payment_address\']').html("");
html = ""