在javascript中,我如何编写一个函数,如果字符串是“选择客户端”,那么地址和联系号码字段应该为空或空白。我已经有了这个功能,如果选择了客户名称,那么地址和联系电话字段将使用 rails 的填充器 gem 自动输入。
$('#client_id').change(function(){
$.ajax({
url: "/fetch_client",
type: "POST",
data: "id="+$(this).attr('value'),
dataType: "json",
success: function(data, textStatus, xhr){
$('#client_address').attr('value',data.client_address);
$('#client_contact_number').attr('value',data.client_contact_number);
},
error: function(xhr, textStatus, errorThrown){
}
});
});
有人可以帮助我,因为我是 javascript 新手吗?