qq_慕标6304929
2020-03-23 16:31
请在预置代码中编写Javascript代码,使预览页面显示如下内容:
Porsche Volvo BMW
任务与要求
请定义数组变量cars,赋值3个元素:Porsche、Volvo、BMW
请使用document.getElementById(id)方法,并结合br换行标签,使id为demo的段落分行显示3个数组元素的值
<html> <head> </head> <body> <label id="demo"></label> <script type="text/Javascript"> var cars = new Array(3); cars[0] = "Porsche"; cars[1] = "Volvo"; cars[2] = "BMW"; var a = document.getElementById("demo") a.innerHTML = cars[0] + "<br>" + cars[1] + "<br>" + cars[2]; </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var cars = ['Porsche', 'Volvo', 'BMW'];
document.getElementById('demo').innerHTML = cars[0]+"<br>";
document.getElementById('demo').innerHTML+= cars[1]+"<br>";
document.getElementById('demo').innerHTML+= cars[2]+"<br>";
</script>
</body>
</html>
这个程序有错误吗
<script type="text/javascript">
var cars= new Array("Porsche","Volvo","BMW");
document.getElemnetById("demo").innerHTML=cars[0]+"<br>"+cars[1]+"<br>"+cars[1]
</script>
//注意这个应该放在demo的后面,如果不是,就需要用js单独写好,然后在demo调用
JavaScript入门篇
739813 学习 · 9566 问题
相似问题