我是Dart语言的新手,但我还在努力!我遇到了这个问题,我想计算乘法表:14。
所以基本上,我希望得到这样的结果: 1400,14,28,42,56,70,84,98,112,126等等
当我打印结果时,我的功能正常工作。但是我无法将结果粘贴到div中。
有我的.dart:
main() {
var numero2 = 14;
var multiplication = 0;
var element02 = query('#exercice02');
for (var i = 1; i < 101; i++) {
multiplication = numero2 * i;
print(multiplication);
}
//element02.text = multiplication;
}
在我的HTML中,我得到了:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HelloWorld</title>
<link rel="stylesheet" href="HelloWorld.css">
</head>
<body>
<div id="container">
<p class="question">Exercice 02 : 100 x 14 : <span id="exercice02"></span></p>
</div>
<script type="application/dart" src="web/HelloWorld.dart"></script>
<script src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script>
</body>
</html>
实际上,我不知道如何对结果进行concatane,我试着你可以看到:element02.text = multiplication;在FOR中,但它会破坏它,然后我尝试+ =并且它们在一起相乘,我最后只有1个结果。
有人可以帮助我吗?
答案 0 :(得分:1)
您希望如何显示结果?喜欢:14, 28, 42
?
<强> test.dart 强>
import 'dart:html';
void main() {
var results = [];
for (var i = 14; i <= 1400; i += 14) {
results.add(i.toString());
}
var element = query('#container');
element.text = Strings.join(results, ', ');
}
<强>的test.html 强>
<!DOCTYPE html>
<html>
<body>
<div id="container"></div>
<script type="application/dart" src="test.dart"></script>
<script src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script>
</body>
</html>
输出:
14,28,42,56,70,84,98,112,126,140,154,168,182,196,210, 224,238,252,266,280,294,308,322,336,350,364,378,392,406, 420,434,448,462,476,490,504,518,532,546,560,574,588,602, 616,630,644,658,672,686,700,714,728,742,756,770,784,798, 812,826,840,854,868,882,896,910,924,938,952,966,980,994, 1008,1022,1036,1050,1064,1078,1092,1106,1120,1134,1148, 1162,1176,1190,1204,1218,1232,1246,1260,1274,1288,1302, 1316,1330,1344,1358,1372,1386,1400