<html>
<head><h3>转化关系</h3></head>
<body>
<p>
<script language="JavaScript" type="text/javascript">
document.bgColor="WHITE";
//document.bgColor="skyblue";
var curNum;
do
{
curNum = prompt("please enter a number","");
}while(isNaN(curNum) == true);
document.write("<table width = 150 border = 2>");
document.write("<tr><th>Mathod</th><th>Result</th></tr>");
document.write("<tr><td>Math.ceil()</td><td>"+ Math.ceil(curNum) +"</td></tr>");
document.write("<tr><td>Math.floor()</td><td>"+ Math.floor(curNum) +"</td></tr>");
document.write("<tr><td>Math.round()</td><td>"+ Math.round(curNum) +"</td></tr>");
document.write("<tr><td>parseInt()</td><td>"+ parseInt(curNum) +"</td></tr>");
document.write("</table>");
</script>
</p><!--段落-->
<p>
<img name=icon src="" border=0 width=150 height=150>
<h1>产生10个1~6的随机数</h1>
<script language="JavaScript" type="text/javascript">
var throwNum;
var diceNum;
for(throwNum = 0; throwNum < 10; throwNum++)
{
<!-- Math.random()*6 产生0~6(不包含6)的随机数,(Math.random()*6)+1 产生0~7(不包含7)的随机数,floor向下取-->
diceNum = Math.floor((Math.random()*6)+1);
document.write(diceNum+"\r\n\t");
}
var names = new Array();
names[0] = "张三";
names[1] = "李四";
names[2] = "王五";
names[11] = "双11";
document.write("<br>");
document.write(names[names.length-1]);<!--打印结果为 双11 -->
<!-- concat() 数组的连接-->
document.write("<br>");
var names = new Array("a", "b", "c");
var ages = new Array("20", "21", "22");
names = names.concat(ages);
var index;
for(index = 0; index < names.length; index++)
{
document.write(names[index]+"\r\t");<!--打印结果为 a b c 20 21 22 -->
}
<!-- join() 将数组转化成字符串-->
var shoping = new Array("apple", "milk","banana","eggs");
document.write("<br>");
document.write(shoping.join());<!--打印结果 apple,milk,banana,eggs-->
document.write("<br>");
document.write(shoping.join("<br>"));<!--这里指定了一个字符"<br>"将它们连接一起,当然也可以不指定-->
<!--排序-->
document.write("<br> 排序 "+shoping.sort());
<!--反转-->
document.write("<br> 反转 "+shoping.reverse());
var dpeth;
dpeth = window.screen.colorDepth;
document.write("<br> 您的计算机颜色是 "+dpeth);
//alert("\n您的计算机颜色位是 "+dpeth);
var myImages = new Array("l.png", "xl.png","xxl.png");<!-- 图片和此文档在同一目录下-->
var imgIndex = prompt("请输入0到2",2);
document.images["icon"].src = myImages[imgIndex];<!-- images是window窗口中document类的属性-->
</script>
</p>
<p>
<A href="scriptday1.html" name="pageOne" οnclick=" return pageOne_onClick() ">点击进入页面1</A><!-- return false 表示不进入链接的页面, 平时可以不用加return语句-->
</p>
<p>
<A href="scriptday1.html" name="pageOne">无指定"onclick"进入页面1的点击</A>
</p>
<script language="JavaScript" type="text/javascript">
function pageOne_onClick()
{
alert("点击确定进入页面1");
return true;
}
<!-- 这是页面无指定点击事件的点击事件调用-->
window.document.links[1].onClick = pageOne_onClick;<!-- links是window窗口中document类的属性-->
</script>
</body>
</html>