jquery 从对象中获取元素 - intl-tel-input 从国家数据中获取拨号代码
jquery get elements from object - intl-tel-input get dial code from country data
我是 jquery 的新手,我想在提交表单后从 intl-tel-input
中的 SelectedCountryData
对象获取值。
从文档中 getSelectedCountryData
return 如下所示,我想从中获取值“93”:
{
name: "Afghanistan (افغانستان)",
iso2: "af",
dialCode: "93"
}
我可以成功 return phone 号码但是 [calling_code] => [object Object]
是 return 当我使用以下调用代码时:
$("form").submit(function() {
$("#phone-full").val($("#phone").intlTelInput("getNumber")); //this works
$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData")); //this doesn't
});
表单输入字段如下:
<input type="tel" id="phone" value="<?php echo $phone_number ?>">
<input id="phone-full" type="hidden" name="phone_number">
<input id="calling_code" type="hidden" name="calling_code">
我设法解决了这个问题,希望它对其他人有用:
$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData").dialCode);
我是 jquery 的新手,我想在提交表单后从 intl-tel-input
中的 SelectedCountryData
对象获取值。
从文档中 getSelectedCountryData
return 如下所示,我想从中获取值“93”:
{
name: "Afghanistan (افغانستان)",
iso2: "af",
dialCode: "93"
}
我可以成功 return phone 号码但是 [calling_code] => [object Object]
是 return 当我使用以下调用代码时:
$("form").submit(function() {
$("#phone-full").val($("#phone").intlTelInput("getNumber")); //this works
$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData")); //this doesn't
});
表单输入字段如下:
<input type="tel" id="phone" value="<?php echo $phone_number ?>">
<input id="phone-full" type="hidden" name="phone_number">
<input id="calling_code" type="hidden" name="calling_code">
我设法解决了这个问题,希望它对其他人有用:
$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData").dialCode);