尝试做一些类似于国家代码侦听器下拉但使用应该填充国家代码的文本框(以便我随后可以在 PHP 代码中使用该值)。
添加事件侦听器不起作用:
<script>
$(document).ready(function(){
$("#mobile").intlTelInput({
onlyCountries: ["au","ca","us","nz","gb"],
utilsScript: "<?php echo get_template_directory_uri(); ?>/intl-tel-input/build/js/utils.js",
geoIpLookup: function(callback) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
},
initialCountry: "auto"
}).addEventListener('countrychange', function() {
$("#country_code").value = "changed"
});;
$('#verify').attr('disabled','disabled');
$("#mobile").on('input', function() {
if ($("#mobile").intlTelInput("isValidNumber")) {
$('#verify').removeAttr('disabled');
$("#country_code").innerHTML = "changed"
} else {
$('#verify').attr('disabled','disabled');
}
});
$("#register-form").submit(function() {
$("#mobile").val($("#mobile").intlTelInput("getNumber"));
});
});
</script>