【发布时间】:2015-06-18 00:40:09
【问题描述】:
我正在为我的一个项目使用intl-tel-input,这是用于国际电话号码的 jQuery 插件。该插件声称“自动将输入占位符设置为所选国家/地区的示例编号”,但我无法使其正常工作。到目前为止,我尝试了两件事:
1) 我下载了该库并从我的代码中引用了其中一个 JS 文件(类似于the demo)。这是我的 JS 文件的 sn-p:
$("#phone").intlTelInput({
allowExtensions: false,
autoFormat: true,
autoHideDialCode: false,
autoPlaceholder: true,
defaultCountry: "ng",
ipinfoToken: "yolo",
nationalMode: true,
numberType: "MOBILE",
onlyCountries: ['ng', 'us', 'gb'],
preferredCountries: [],
utilsScript: "/projects/intl-tel-input-master/lib/libphonenumber/build/utils.js"
});
但是我在 Chrome 的 JS 控制台中出现以下错误:
XMLHttpRequest 无法加载 file:///projects/intl-tel-input-master/lib/libphonenumber/build/utils.js。跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。
2) 我将库文件夹放在服务器上,并使用服务器 url (http://web.mit.edu/aizhan/www/intl-tel-input-master/lib/libphonenumber/build/utils.js) 引用了 utils.js 文件。这仍然无法在我的机器上使用,但它可以在带有 HTTP 协议的 codepen 中使用,但不适用于 HTTP:
HTTP:http://codepen.io/atoregozh/pen/raEPbv
HTTPS:https://codepen.io/atoregozh/pen/MYMLXv
我的总体问题:我怎样才能使图书馆在本地工作?我也有 2 个子问题: 1)如何解决有关 XMLHttpRequest 加载的错误? (我之前从 stackoverflow 上的其他帖子中读到过它,我不想弄乱安全设置); 2) 为什么代码通过 HTTP 而不是通过 HTTPS 工作?
非常感谢您的帮助。如果想看实际项目代码,the index.html file is here 和Javascript file is here
【问题讨论】:
标签: javascript jquery jquery-plugins contentplaceholder