TypeScript代码如下:
namespacesLab.ts:
var ArrayUtilities; (function (ArrayUtilities) { function reverseArray(array) { return array.slice(0).reverse(); } ArrayUtilities.reverseArray = reverseArray; function lastItemOfArray(array) { return array.slice(0).pop(); } ArrayUtilities.lastItemOfArray = lastItemOfArray; function firstItemOfArray(array) { return array.slice(0).shift(); } ArrayUtilities.firstItemOfArray = firstItemOfArray; function concatenateArray(array1,array2) { return array1.concat(array2); } ArrayUtilities.concatenateArray = concatenateArray; })(ArrayUtilities || (ArrayUtilities = {}));
HTML代码如下:
index.html的:
<script src="namespacesLab.js"></script> <html> <body> <script> array1 = [1,2,3,4,5]; array2 = [6,7,8,9,10]; function callArrayUtil(util,array,array2 = null) { document.getElementById("output").innerHTML = ArrayUtilities[util]( array,array2 ).toString(); } document.getElementById("output").innerHTML = array1.toString(); </script> <div id="output " style="width:100%;"></div> <button onclick="callArrayUtil('reverseArray',array1)"> Reverse Array </button> <button onclick="callArrayUtil('lastItemOfArray',array1)"> Last Item of Array </button> <button onclick="callArrayUtil('firstItemOfArray',array1)"> First Item of Array </button> <button onclick="callArrayUtil('concatenateArray',array1,array2)"> Concatenate Array </button> </body> </html>
当我点击index.html时,会出现一个显示四个按钮的网页.但是,没有显示数组.
预期结果:网页上显示四个按钮和一个数组
实际结果:数组没有显示在网页上
解决方法
您的ID中有空格:
更改
<div id = "output " style = "width:100%;">
至
<div id = "output" style = "width:100%;">
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。