李秋 发表于 2013-1-4 02:45:27

JS 总结

JS 总结

    <div class="postText"><div id="cnblogs_post_body">计算网站开了多少天
<script>
var now = new Date();
var firstday = new Date("2-1-2005");
var msperday = 60*60*25*1000;
var days = now – firstday;
days = Math.round( days/msperdays );
</script>
document对象
返回当前文件的URLdocument.URL 或者document.location例如:http://www.zixingchewang.com/test.html?id=54
返回浏览器的域名document.domain例如:www.zixingchewang.com
返回锚点的数量document.anchors.length
获取下拉菜单的信息:
mylist.options.txt
Document.getElementbyId('id').selectIndex
This.value = Document.getElementbyId('id').value
时间转变成时间戳:time.toUTCString()
页面跳转:
    后退上一页:history.go(-1);
    跳转:location.href = 'newpage.html';
定时一分钟执行一次:timeout=setTimeout( "fun_name()", 60 );结束执行:clearTimeout(timeout)
第一个和最后一个单元格的引用:
    var allTDs = document.getElementById("tdName");
    var firstTD = allTDs.item(0).id
    var lastTD = allTDs.item(allTDs.length-1).id
返回变量的类型:typeof()
类型转换:parseInt()方法,将以数字开头的字符化为整数
    parseInt( '3page' );结果3
    parseInt('18ff',16);结果6399
    parseInt('18ff',10);结果18
    parseInt('ff',10);结果NAN
将字符串参数当表达式:eval("5*4*3") 结果 60
转变成URL编码:escape反之:unescape
forin 循环
var obj=new Object();
obj.name='李秋';obj.age=22;obj.photo=123456;
for( prop in obj )
{
document.write( "属性"+prop+"="+obj );
}
string对象
    toLowerCase()变成小写
    toUpperCase()变成大写
    charAt(index) 返回index字符(从0开始)
    charCodeAt(index) 返回index字符的UNICODE编码
    replace( "str1","str2" ) 将str1代替str2
    split(str) 返回array对象,使用str分割转化为array对象
    Number()字符转化成数字
Array对象
    length()树组的长度
    join()树组元素使用,连接
    reverse()反转
    sort()排序
    concat(array) 合并树组
radom()返回随即数
round()返回四舍五入后的数
获得HTML标签的<p>的属性document.all.tags('p').item(0).align
处理属性
    getAttribute(attribute)获得属性
    setAttribute(attribute,value)设置属性
    removeArribute(attribute)删除属性
数字转化成为字符String.fromCharCode(65)结果 A
函数(对象)
    每个函数声明后都有arguments对象
可以通过arguments的方式来访问每一个参数,
可以通过arguments对象的callee属性来得到正在执行的函数对象的引用
可以通过arguments对象的caller属性来得到父函数对象的引用
判断变量是否存在
    typeof(myvalue)=="undefined")
   
ajax
当ajax请求没有结束前刷新页面,那么可能提前结束ajax请求。
页: [1]
查看完整版本: JS 总结