我正在尝试按照 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
我曾尝试更改脚本中注释掉的选项,但没有帮助。
原文由 Abhishek Singh 发布,翻译遵循 CC BY-SA 4.0 许可协议
好的,我解决了这个问题。所以基本上这里是必须为真的选项字段,我们需要在
</head>
标记之前放置以下脚本。脚本:
将它放在关闭 head 标签之前,并记得调用
$("#mobile-number").intlTelInput();
因为这很重要。