javascript学习笔记,绝对值,倒计时,按数字计算
2013-04-15 09:34
597 查看
1.javascript强制按照数字计算:
2.javascript取绝对值:
3.javascript倒计时:
4.js+css实现禁止选择文字:
5.js向上向下取整,四舍五入:
6.js保留两位小数
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
相关文章推荐
- Javascript学习笔记:2种其他类型转换为数字Number类型的方式
- javascript 学习笔记(四) 倒计时程序代码
- JavaScript学习笔记(4)数字和字符串
- JavaScript中的Number数字类型学习笔记
- javascript学习笔记--数字格式类型
- javascript学习笔记(四) Number 数字类型
- javascript学习笔记--数字格式类型
- [学习笔记—算法] 计算整数各位上数字的和
- javascript 学习笔记(四) 倒计时程序代码
- javascript学习笔记(四) Number 数字类型
- javascript学习笔记(四) Number 数字类型
- JavaScript学习笔记之惰性函数示例详解
- javascript学习笔记(一) 在html中使用javascript
- JavaScript学习笔记之ES6数组方法
- AngularJs学习笔记__6、自定义过滤器,阿拉伯数字金额转汉字金额
- javascript学习笔记——表达式和运算符
- [学习笔记]JavaScript基础
- Javascript学习笔记(Object 对象与继承)
- 【学习笔记javascript设计模式与开发实践(闭包和高阶函数)----3】
- JavaScript学习笔记(09)之文档对象模型DOM