我当前的代码是(在标题和正文标签等之间):
<script>
var products = ["Printer", "Router", "Tablet", "Keyboard", "Javascript", "HTML"];
products.sort();
document.write(products);
<br></br>
document.write("The amount of products in the array is " + products.length);
</script>
但是,当我运行此代码时,网页上没有任何内容。
如前所述,这是使用Dreamweaver,特别是dreamweaver CS5。
谁能告诉我如何在显示"document.write(products)"的行和最后一个document.write之间换个断点,而不会消失我的所有代码?
谢谢
通常你不应该使用document.write
除非你确切地知道你在做什么,否则尝试做这样的事情:
<div id="output"></div>
<script>
var products = ["Printer", "Router", "Tablet", "Keyboard", "Javascript", "HTML"];
products.sort();
var el = document.getElementById('output');
el.innerHTML = products.join(', ') + '<br>'
+ "The amount of products in the array is " + products.length;
</script>