我正在尝试将模块导入我的index.html文件。
代码如下:
// Index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div></div>
<script type="module" src="module.js"></script>
<script type="text/javascript">
import { addTextToBody } from 'module.js';
addTextToBody('some text here');
</script>
</body>
</html>
还有js:
export function addTextToBody(text) {
const div = document.createElement('div');
div.textContent = text;
document.body.appendChild(div);
}
我遇到这些错误:
未捕获的SyntaxError:意外令牌{-第18行
CORS策略已阻止从源“ null”访问“ module.js”处的脚本:无效响应。因此,不允许访问原始“空”。
我该如何解决?
答案 0 :(得分:2)
<html lang="en">
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<link rel="stylesheet" href="css/app.css"/>
<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
-->
<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-route.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>
<script>
var app = angular.module('myApp',[]);
app.directive('myDirective',function(){
return function(scope, element,attrs) {
element.bind('click',function() {alert('click')});
};
});
</script>
</head>
<body ng-app="myApp">
<div >
<button my-directive>Click Me!</button>
</div>
<h1>{{2+3}}</h1>
</body>
</html>
应该是module.js
./module.js
要求脚本的类型为import
,而不仅仅是导入的脚本。module
中(一开始)。以下示例有效(我裁掉了不必要的部分):
<head>
<!-- index.html -->
<meta charset="utf-8">
<script type="module">
import { addTextToBody } from './module.js';
addTextToBody('some text here');
</script>
以上提供的代码适用于Firefox,但不适用于Chrome。看来您使用的是Chrome(我从您的错误消息中得出结论)。 Chrome严格禁止使用// module.js
export function addTextToBody(text) {
const div = document.createElement('div');
div.textContent = text;
document.body.appendChild(div);
}
协议访问资源。有几种解决方案:
答案 1 :(得分:0)
尝试:
>>> print(lxml.etree.tostring(root, pretty_print=True).decode())
<SchemeData xmlns="Boo">
<Equipment>
<SigEquipment fileUID="30734" name=""/>
</Equipment>
<Equipment>
<SigEquipment fileUID="31597" name=""/>
</Equipment>
</SchemeData>