Jquery国际电话号码输入

时间:2015-03-05 16:34:34

标签: javascript jquery

我正在尝试关注http://www.jqueryscript.net/form/jQuery-International-Telephone-Input-With-Flags-Dial-Codes.html上的jquery教程,以便在表单中创建包含国家/地区代码的输入类型编号。但是,在我的情况下,虽然标志似乎发生了变化,但国家代码并未添加到输入字段中,因为它们在演示中显示。

以下是他们提供的代码:

<head>
<meta charset="utf-8">
<title>International Telephone Input</title>
<link rel="stylesheet" href="build/css/intlTelInput.css">
<link rel="stylesheet" href="build/css/demo.css">
</head>
   <body>

<form>
  <input id="mobile-number" type="tel">
  <button type="submit">Submit</button>
</form>

<!-- Load jQuery from CDN so can run demo immediately -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="build/js/intlTelInput.js"></script>
<script>
  $("#mobile-number").intlTelInput({
    //allowExtensions: true,
    //autoFormat: false,
    //autoHideDialCode: false,
    //autoPlaceholder: false,
    //defaultCountry: "auto",
    //ipinfoToken: "yolo",
    //nationalMode: false,
    //numberType: "MOBILE",
    //onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
    //preferredCountries: ['cn', 'jp'],
    //preventInvalidNumbers: true,
    utilsScript: "lib/libphonenumber/build/utils.js"
  });
</script>

以下是我尝试实施该链接的链接:https://www.easyaccom.com/mobile/verifynumber.html

我尝试在脚本中更改已注释的选项,但它没有帮助。

6 个答案:

答案 0 :(得分:3)

好的我解决了这个问题。 所以基本上这里的选项字段必须为true,我们需要在</head>标记之前放置以下脚本。

脚本:

<script>
$(function() {
$("#mobile-number").intlTelInput({
allowExtensions: true,
autoFormat: false,
autoHideDialCode: false,
autoPlaceholder: false,
defaultCountry: "auto",
ipinfoToken: "yolo",
nationalMode: false,
numberType: "MOBILE",
//onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
//preferredCountries: ['cn', 'jp'],
preventInvalidNumbers: true,
utilsScript: "lib/libphonenumber/build/utils.js"
});
});
</script>

在关闭head标记之前放置它,并记住调用$("#mobile-number").intlTelInput();,因为它很重要。

答案 1 :(得分:1)

您只是忘记将您的jquery代码放在de document.ready。

见下文:

$(document).ready(function(){

    $("#mobile-number").intlTelInput({
        //allowExtensions: true,
        //autoFormat: false,
        //autoHideDialCode: false,
        //autoPlaceholder: false,
        //defaultCountry: "auto",
        //ipinfoToken: "yolo",
        //nationalMode: false,
        //numberType: "MOBILE",
        //onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
        //preferredCountries: ['cn', 'jp'],
        //preventInvalidNumbers: true,
        utilsScript: "lib/libphonenumber/build/utils.js"
    });
});

答案 2 :(得分:1)

国家/地区代码将始终位于输入字段中,并带有此代码

val model = XGBoost.train(trainData3, paramMap, round=2, nWorkers=2, useExternalMemory=true, missing=0.0f ) 

答案 3 :(得分:0)

&#13;
&#13;
$(function() {
$("#mobile-number").intlTelInput({
   autoHideDialCode: false,
   autoPlaceholder: false,
   nationalMode: false
});
});
&#13;
&#13;
&#13;

答案 4 :(得分:0)

为什么国家/地区代码和国家/地区代码在页面回发后不稳定。

这是我到目前为止所尝试的内容:

<script>
        $(document).ready(function () {
            $("#Phone").intlTelInput({
                allowDropdown: true,
                // autoHideDialCode: false,
                // autoPlaceholder: "off",
                // dropdownContainer: "body",
                // excludeCountries: ["us"],
                defaultCountry: "auto",
                // formatOnDisplay: false,
                //geoIpLookup: function (callback) {
                //    $.get("http://ipinfo.io", function () { }, "jsonp").always(function (resp) {
                //        var countryCode = (resp && resp.country) ? resp.country : "";
                //        callback(countryCode);
                //    });
                //},
                //initialCountry: "auto",
                // nationalMode: false,
                // onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
                // placeholderNumberType: "MOBILE",
                // preferredCountries: ['in','pk', 'np','bd', 'us','bt','sg','lk','ny','jp','hk','cn'],
                // separateDialCode: true,
                utilsScript: "build/js/utils.js"
            });

            $("#Phone").on("countrychange", function (e, countryData) {
                $("#hdnPhone").val(countryData.dialCode);
            });
        });
  </script>
<script>
        $(document).ready(function () {
            $("#Phone").val('');
            var HdnVal = $("#hdnPhone").val();

            if (HdnVal != '') {
                var countryData = $("#Phone").intlTelInput("getSelectedCountryData");

                $("#hdnPhone").val(countryData.dialCode);
            }
        });

    </script>

答案 5 :(得分:0)

try this code

$("#mobile-number").intlTelInput({
       // allowExtensions: true,
       //autoFormat: false,
        autoHideDialCode: false,
       // autoPlaceholder: false,
       // defaultCountry: "auto",
        //ipinfoToken: "yolo",
        nationalMode: false,
       // numberType: "MOBILE",
       // onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
        //preferredCountries: ['cn', 'jp'],
        //preventInvalidNumbers: true,
        utilsScript: "lib/libphonenumber/build/utils.js"
    });
});