问题:
在不需要js的情况下,这是如何正常工作的:
https://jsfiddle.net/3xL745fu/
<script src="https://unpkg.com/libphonenumber-js@1.7.18/bundle/libphonenumber-min.js">
</script>
<script>
alert(new libphonenumber.AsYouType('US').input('213-373-4253'))
</script>但是使用了require js:
https://jsfiddle.net/vwu84jap/
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script src="https://unpkg.com/libphonenumber-js@1.7.18/bundle/libphonenumber-min.js">
</script>
<script>
alert(new libphonenumber.AsYouType('US').input('213-373-4253'))
</script>libphonenumber未定义?
发布于 2019-05-20 18:43:04
解决方案是通过require js加载js:
<script src="https://cdnjs.cloudflare.com/ajax/libs/libphonenumber-js/1.7.18/libphonenumber-js.min.js">
</script>
<script>
require([
'libphonenumber'
], function (libphonenumber) {
'use strict';
console.log("libhphone number working");
window.alert(new libphonenumber.AsYouType('US').input('213-373-4253'))
});
</script>https://stackoverflow.com/questions/56219230
复制相似问题