javascript之基础知识
---恢复内容开始---
javascript·基础知识
知识体系:var->array->function->event
1)JS的'+'
因为+会被理解为字符串的连接 所以在这样一种情况下,获取文本框的值进行加法要parseInt(txt1)+parseInt(txt2);
关于parseInt() 参照下面的链接
http://blog.csdn.net/ufo2910628/article/details/40735691
2)对象 字符串 数值 函数 对象有属性和方法
Date():getFullYear() getMonth() getDate() getDay():ps(返回的是0~6对应的星期 可用数组对应星期几) setTime():ps(计算从1970年1月1日零食起的毫秒)
String:toUpppercase() charAt() indexof() substr() split()
Math:abs() ceil() floor() round() random()ps:(return 0~1)
Array():concat [split<->join(连接 比如join(" "))] reverse() slice():start 到 end(不包括该元素)ps:选定元素(String Array的slice 类似) sort(sortMethod)
常用方法总结:split(";") ->将字符串转为数组 然后遍历 ...
3)window对象
setInterval-clearInterval -- setTimeout-clearTimeout
history Method[back,forward,go]
location(获取对象窗口的URL href(连接到一个新的地址) hostname pathname ...]Method[assign
navigator(返回浏览器的信息) useragent platform
screen width height availWidth
编写js遇到的一些问题:
1:目标:一秒变换颜色的字体
注意:toString(16)是->16进制的方法
http://www.cnblogs.com/muguaworld/archive/2008/07/18/1246338.html
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 5 </head> 6 <body> 7 <!-- 字体变色--> 8 <h2 id="con"> I lOVE JAVASCRIPT</h2> 9 <h3 id="h3">SOAM I</h3> 10 <input type="text" id="t" value="1"> 11 </body> 12 <script type="text/javascript"> 13 17 var _M24=Math.pow(2,24);19 function randomcolor(){ 20 return "#"+("00000"+(Math.round(Math.random()*_M24)).toString(16)).slice(-6); 21 } 22 var con=document.getElementById("con"); 23 var h3=document.getElementById("h3"); 24 var text=document.getElementById("t"); 25 26 var colors=["red","yellow","black","blue"]; 27 28 var count=0; 29 function change(){ 30 con.style.color=colors[count]; 31 count++; 32 if(count==4)count=0; 33 } 34 function change2(){ 35 h3.style.color=randomcolor(); 36 } 37 var i=setInterval(change,1000); 38 var i2=setInterval(change2,1000); 39 </script> 40 </html>
---恢复内容结束---