CONTACTO
Un representante de Chilat estará en contacto dentro de las 48 horas para organizar una consulta inicial y guiarle a través del proceso.
const countries = [
{country: "Argentina", code: "+54"},
{country: "Bolivia", code: "+591"},
{country: "Chile", code: "+56"},
{country: "Colombia", code: "+57"},
{country: "Costa Rica", code: "+506"},
{country: "Cuba", code: "+53"},
{country: "Ecuador", code: "+593"},
{country: "El Salvador", code: "+503"},
{country: "España", code: "+34"},
{country: "Guatemala", code: "+502"},
{country: "Honduras", code: "+504"},
{country: "México", code: "+52"},
{country: "Nicaragua", code: "+505"},
{country: "Panamá", code: "+507"},
{country: "Paraguay", code: "+595"},
{country: "Perú", code: "+51"},
{country: "Puerto Rico", code: "+1787"},
{country: "República Dominicana", code: "+1890"},
{country: "Uruguay", code: "+598"},
{country: "Venezuela", code: "+58"},
{country: "Otro", code: "+000"},
{country: "Estados Unidos", code: "+1"},
]
// 获取下拉选择元素
let whatsapp = document.getElementById("input_12_4")
let country = document.getElementById('input_12_20');
// Whatsapp添加 change 事件监听器
// 默认添加阿根廷的区号
whatsapp.addEventListener('change', function(event) {
document.getElementById("input_12_4").value = event.target.value?.replace(/\(([^)]+)\)/g, '');
// 事件处理逻辑
const target = countries?.find((item) => {
return event.target.value.startsWith(item.code)
})
const result = countries?.find((item) => {
return item.country === country.value
})
if (!target) {
document.getElementById("input_12_4").value = (result?.code||"+54")+event.target.value
}
});
// 国家添加 change 事件监听器
country.addEventListener('change', function(event) {
countries?.forEach((item) => {
if (whatsapp.value?.startsWith(item.code)) {
whatsapp.value = whatsapp.value?.substring(item.code.length);
}
})
// 获取用户选择的值
let selectedValue = event.target.value;
let target = countries?.find((item) => {
return item.country === selectedValue;
})
// 执行相关操作
document.getElementById("input_12_4").value = target?.code+whatsapp.value
});