您现在的位置是:网站首页> HTML&JS
浏览器中使用import
- HTML&JS
- 2022-03-05
- 724人已阅读
页面文件内容:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0">
</head>
<body>
<button onclick="hello1()">执行1</button> <button onclick="hello2()" style="margin-left:10px;">执行2</button>
<script type="module">
//function hello1()
//{
import { foo,name} from 'http://www.1xn1.com/JsonMode/代码工厂/View//amazeui/public/js/foo.js';
import { foo2,nale,age} from 'http://www.1xn1.com/JsonMode/代码工厂/View//amazeui/public/js/foo2.js';
window.foo=foo;
window.fname=name;
window.foo2=foo2;
window.nale=nale;
window.age=age;
alert(foo());
alert(name);
// }
</script>
<script>
function hello1()
{
alert(foo());
}
function hello2() {
alert(foo2());
alert(nale);
alert(age);
}
</script>
</body>
</html>
foo.js文件内容:
export function foo() {
return 'bar';
}
export var name='徐子童';
foo2.js文件内容:
function foo2() {
return 'bar';
}
var name='橙汁';
var age = 28;
export{foo2,name as nale, age}