我正在尝试将intlTelInput
插件集成到 AMP 页面中。该插件工作正常,但 AMP 抛出错误(不允许自定义 javascript)。
插件信息 https://github.com/jackocnr/intl-tel-input
为了更清楚,我附上了一个错误截图。
下面是代码片段。
<!doctype html>
<html ⚡ lang="en">
<head>
<meta charset="utf-8">
<meta name="amp-script-src" content="sha384-05IkdNHoAlkhrFVUCCN805WC_h4mcI98GUBssmShF2VJAXKyZTrO_TmJ-4eBo0Cy">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="self.html" />
<style amp-boilerplate>
body {
-webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
animation: -amp-start 8s steps(1, end) 0s 1 normal both;
}
@-webkit-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@-moz-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@-ms-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@-o-keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
@keyframes -amp-start {
from {
visibility: hidden;
}
to {
visibility: visible;
}
}
</style>
<noscript>
<style amp-boilerplate>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style>
</noscript>
<style amp-custom>
@import "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/css/intlTelInput.css";
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/js/intlTelInput.min.js" type="text/javascript"></script>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
</head>
<body>
<div class="container">
<section class="todoapp">
<amp-script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/js/intlTelInput.min.js" layout="container">
<input id="phone" name="phone" type="tel">
<button type="submit">Submit</button>
</amp-script>
<script type="text/javascript">
var input = document.querySelector("#phone");
window.intlTelInput(input, {
autoHideDialCode: false,
geoIpLookup: function(callback) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
},
initialCountry: "auto",
nationalMode: false,
});
</script>
</section>
</div>
</body>
</html>