zoukankan      html  css  js  c++  java
  • javascript学习笔记,绝对值,倒计时,按数字计算

    1.javascript强制按照数字计算:

    var a="12";
    var b="34";
    alert(a+b);// 输出"1234"
    alert((+a)+(+b));// 输出"46"

    2.javascript取绝对值:

    alert(Math.abs(-1));// 输出1
    alert(Math.abs(1));// 输出1

    3.javascript倒计时:

    var time=3;
    var timeStr=["零","一","二","三"];
    setInterval("send()",1000);
    function send(){
        if(time>0){
            document.getElementById("num").innerHTML=timeStr[time-1];
            time--;
            return;
        }
        window.parent.location.replace("<%=basePath%>#");
    }

    4.js+css实现禁止选择文字:

    1.firefox中给需要禁止选择文字的地方,加上样式:-moz-user-select:none;
    2.ie中给需要禁止选择文字的标签,加上onselectstart="return false"事件

    5.js向上向下取整,四舍五入:

    1. Math.ceil()用作向上取整。 
    2. Math.floor()用作向下取整。 
    3. Math.round() 我们数学中常用到的四舍五入取整。 
    alert(Math.ceil(10/3));// 输出4
    alert(Math.floor(10/3));// 输出3
    alert(Math.round(10/3));// 输出3

    6.js保留两位小数

    12.12333.toFixed(2)-->12.12
  • 相关阅读:
    django 如何重用app
    vim常用命令
    linux find grep
    linux su su-的区别
    linux定时任务crontab
    linux shell的单行多行注释
    python字符串的截取,查找
    gdb调试
    python字符转化
    python读写文件
  • 原文地址:https://www.cnblogs.com/zhouyalei/p/3021458.html
Copyright © 2011-2022 走看看