【发布时间】:2016-08-27 01:25:38
【问题描述】:
你好,我刚开始学习一些飞镖,我也是这个论坛的新手,
我用 webstorm 创建了超级简单的 webapp,并编写了一个非常简单的 dart 脚本和一个 html 文档。
我的 html 文档的头部:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/google/stagehand">
<title>Das bist du!</title>
<script defer src="http://das-bist-du.com/main.dart" type="application/dart"></script>
<script defer src="http://das-bist-du.com/packages/browser/dart.js"> </script>
</head>
<body>
</body>
</html>
飞镖代码:
import 'dart:html';
import 'dart:math';
ButtonElement rndButton;
ImageElement rndImage;
var images;
var rng;
void main() {
rndButton = querySelector('#rndButton');
rndImage = querySelector('#imgScreen');
images = ['http://das-bist-du.com/onewebmedia/anN0MBo_700b.jpg', 'http://das-bist-du.com/onewebmedia/du1.jpg', 'http://das-bist-du.com/onewebmedia/du2.jpg', 'http://das-bist-du.com/onewebmedia/du3.jpg', 'http://das-bist-du.com/onewebmedia/du3.jpg', 'http://das-bist-du.com/onewebmedia/du4.jpg', 'http://das-bist-du.com/onewebmedia/du5.jpg', 'http://das-bist-du.com/onewebmedia/du6.jpg'];
rndButton.onClick.listen(pickYou);
}
void pickYou (Event e) {
rng = new Random();
setYou(rng.nextInt((images.length)));
}
void setYou (var rnd) {
print(images[rnd].toString());
rndImage.src = (images[rnd].toString());
}
我知道代码并不漂亮,我只是在测试。 :)
现在我想在网站上同时使用两者,我将 html 页面的代码和 dart.js 上传到网站,并将 src 放在 html 脚本标签中。
在使用 Chromium 在 Webstorm 中进行测试时,它可以工作。 但该脚本不在网站上运行。如何在网站上在线使用 dart?
提前致谢
【问题讨论】: