JavaScript -- 猜数、遍历
2014-05-12 00:07
141 查看
----- 004-猜数.html -----
![](http://images.cnitblog.com/i/629678/201405/120004376986287.jpg)
----- 005-遍历.html -----
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>猜数</title> </head> <body> <script type="text/javascript"> document.write("猜数游戏,0到100<br/>"); theNo = Math.round(Math.random()*100); x = window.prompt("请输入要猜的数字:"); count = 1; while(x != theNo) { document.write("猜了"+count+"次了<br>") count ++; if(x < theNo) x = window.prompt("太小,请重猜:"); else x = window.prompt("太大,请重猜:"); } document.write("你猜了"+count+"次,终于") document.write("猜对了!是"+theNo); </script> </body> </html>
![](http://images.cnitblog.com/i/629678/201405/120004376986287.jpg)
----- 005-遍历.html -----
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Titanic</title> </head> <body> <script type="text/javascript"> var ti = new Object(); ti.name = "泰坦尼克号"; ti.weight = "46328吨"; ti.sunkTime = "1912年4月14日晚11点40分"; for(prop in ti) { document.write("属性:"+prop+"<br/>"); document.write("值:"+ti[prop]+"<br/><br/>") } </script> </body> </html>
![](http://images.cnitblog.com/i/629678/201405/120006070572654.jpg)
相关文章推荐
- JavaScript中for-in遍历方式示例介绍
- JavaScript中的数组遍历forEach()与map()方法以及兼容写法介绍
- Javascript 数组循环遍历之forEach
- 从零开始学_JavaScript_系列(35)——继承与遍历的对照表
- JavaScript之对象的遍历
- JavaScript遍历DOM
- JavaScript 数组所有遍历数组方法
- 用JavaScript语言通过DOM遍历XML文档
- JavaScript遍历XML总结
- 如何利用JavaScript遍历JSON数组
- [ javasript ] javascript中的each遍历!
- JavaScript递归遍历输出json所有字段与值的方法
- javascript实现二叉树递归遍历和非递归遍历
- js中foreach,for in,for of的使用及区别,遍历对象,遍历数组使用的不一样 JavaScript
- Javascript 数组循环遍历之forEach
- Javascript 数组循环遍历之forEach
- javascript遍历map
- JQuery $.each遍历JavaScript数组对象实例
- Javascript 遍历页面text控件详解