<!DOCTYPE html> <html> <head> <table>常用函数</table> <meta charset="utf-8"> </head> <body> <h1>Array 数组</h1> 原始数据: <sapn id="originalArray"></sapn><br /> slice(1,3) 索引1,2的数据: <span id="sliceoriginalArray"></span><br /> sort 排序: <span id="sortoriginaArray"></span><br /> <h1>--时间--</h1> 当前时间:<span id="spnCurrentDate"></span><br /> 指定时间:<span id="spnTempDate"></span><br /> <h1>Math 对象用于执行数学任务</h1> math.random 随机数 0-1之间<span id="spnRandom"></span><br /> math.round(9.8) 把一个数字舍入为最接近的整数之间<span id="spnRound"></span><br /> math.ceil(9.1) 对一个数进行上舍入:<span id="spnCeil"></span><br /> math.floor(9.8) 返回小于等于x的最大整数:<span id="spnFloor"></span><br /> math.PI 圆周率<span id="spnPI"></span><br /> 计算eval("2+2*3"):<span id="spnEval"></span> </body> <script type="text/javascript"> var originalArrays = new Array(); originalArrays[0] = "马超"; originalArrays[1] = "赵云"; originalArrays[2] = "刘备"; originalArrays[3] = "黄忠"; originalArrays[4] = "张飞"; originalArrays[5] = "关羽"; //Date var currentDate = new Date(); document.getElementById("spnCurrentDate").innerText = currentDate; var tempDate = new Date(); tempDate.setFullYear(2028, 08, 08); tempDate.setHours(08, 08, 08); document.getElementById("spnTempDate").innerText = tempDate; var sliceoriginalArrays = originalArrays.slice(1, 3); var sortoriginaArrays = JSON.parse(JSON.stringify(originalArrays)).sort() document.getElementById("originalArray").innerText = originalArrays.toString(); document.getElementById("sliceoriginalArray").innerText = sliceoriginalArrays.toString(); document.getElementById("sortoriginaArray").innerText = sortoriginaArrays.toString(); document.getElementById("spnRandom").innerText = Math.random(); document.getElementById("spnRound").innerText = Math.round(9.8); document.getElementById("spnCeil").innerText = Math.ceil(9.1); document.getElementById("spnFloor").innerText = Math.floor(9.8); document.getElementById("spnPI").innerText = Math.PI; document.getElementById("spnEval").innerHTML = eval("2+2*3"); </script> </html>
标签:常用,函数,08,javaScript,originalArrays,getElementById,innerText,document,Math From: https://www.cnblogs.com/dwdw/p/16729494.html