zoukankan      html  css  js  c++  java
  • JS 总结

    计算网站开了多少天

    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 );

    document对象

    1. 返回当前文件的URL document.URL 或者document.location 例如:http://www.zixingchewang.com/test.html?id=54
    2. 返回浏览器的域名 document.domain 例如:www.zixingchewang.com
    3. 返回锚点的数量 document.anchors.length

    获取下拉菜单的信息

    mylist.options[mylist.selectedIndex].txt
    Document.getElementbyId('id').selectIndex
    This.value = Document.getElementbyId('id').value

    时间转变成时间戳 

    time.toUTCString()

    页面跳转

    1. 后退上一页:history.go(-1);
    2. 跳转: 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()方法,将以数字开头的字符化为整数

    1. parseInt( '3page' ); 结果 3
    2. parseInt('18ff',16); 结果 6399
    3. parseInt('18ff',10); 结果 18
    4. parseInt('ff',10); 结果 NAN
    5. 将字符串参数当表达式: eval("5*4*3") 结果 60

    转变成URL编码: escape 反之: unescape

    for in 循环

    var obj=new Object();
    obj.name='李秋';    obj.age=22;    obj.photo=123456;
    for( prop in obj )
    {
         document.write( "属性"+prop+"="+obj[prop] );
    }

    string对象

    1. toLowerCase() 变成小写
    2. toUpperCase() 变成大写
    3. charAt(index) 返回index字符(从0开始)
    4. charCodeAt(index) 返回index字符的UNICODE编码
    5. replace( "str1","str2" ) 将str1代替str2
    6. split(str) 返回array对象,使用str分割转化为array对象
    7. Number() 字符转化成数字

    Array对象

    1. length() 树组的长度
    2. join() 树组元素使用,连接
    3. reverse() 反转
    4. sort() 排序
    5. concat(array) 合并树组
    6. radom() 返回随即数
    7. round() 返回四舍五入后的数

    获得HTML标签的<p>的属性 document.all.tags('p').item(0).align

    处理属性

    1. getAttribute(attribute) 获得属性
    2. setAttribute(attribute,value) 设置属性
    3. removeArribute(attribute) 删除属性

    数字转化成为字符 String.fromCharCode(65) 结果 A

    函数(对象)

    • 每个函数声明后都有arguments对象
    • 可以通过arguments[n]的方式来访问每一个参数,
    • 可以通过arguments对象的callee属性来得到正在执行的函数对象的引用
    • 可以通过arguments对象的caller属性来得到父函数对象的引用

    判断变量是否存在
    typeof(myvalue)=="undefined")

  • 相关阅读:
    【PHP设计模式 08_CeLue.php】策略模式
    【PHP设计模式 07_ZeRenLian.php】责任链模式
    【PHP设计模式 06_GuanChaZhe.php】观察者模式
    【PHP设计模式 05_DanLi.php】单例模式
    【PHP设计模式 04_GongChang.php】 工厂方法
    【PHP设计模式 03_JianDanGongChang.php】 简单工厂
    【PHP设计模式 02_JieKou.php】面向接口开发
    区块链学习-开始
    erc721-165学习
    cryptopunks的代码解释
  • 原文地址:https://www.cnblogs.com/liqiu/p/2557395.html
Copyright © 2011-2022 走看看