我一直试图输入手机号码的扩展名。每个其他变量都正常工作。扩展变量返回Null。它似乎正在将空值传递给POST。
<input type="tel" id="mobile" placeholder="Mobile Number" maxlength="10" >
<script>
//Initialize the plugin
$("#mobile").intlTelInput({
initialCountry: "auto",
nationalMode: "true",
utilsScript:'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/8.5.0/js/utils.js',
geoIpLookup: function(callback) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
}
});
//Ajax Registration
$("#register").click(function(){
var email = $("#email").val();
var password = $("#password").val();
var confirmpassword = $("#confirmpassword").val();
var fname = $("#fname").val();
var lname = $("#lname").val();
var mobile = $("#mobile").val();
var role = $("#role").val();
var extension = $("#mobile").intlTelInput("getExtension");
var data = "email=" + email + "&password=" + password + "&fname=" + fname + "&lname=" + lname + "&mobile=" + mobile + "&role=" + role + "&confirmpassword=" + confirmpassword + "&extension=" + extension;
$.ajax({
type:"POST",
url:"includes/register.php?",
data:data,
success:function(data)
{
$("#register_output").html(data);
}
});
</script>
答案 0 :(得分:0)
我相信现在不赞成使用getExtension方法。如果您想单独使用国家/地区代码,请访问iti.s.dialCode
。像这样:
<label>Phone</label><input class="textbox" type="tel" name="phone" id="phone" value=""><br>
<script>
var input = document.querySelector('#phone');
var iti = intlTelInput(input, {
utilsScript: 'assets/tel-input/js/utils.js',
initialCountry: 'au'
});
$('#send').on('click', function(param) {
var fullPhone = "+" + iti.s.dialCode + iti.getNumber();
console.log(fullPhone)
});
</script>