一、数据处理篇
1、JS取整函数
(1)丢弃小数部分,保留整数部分
js:parseInt(7/2)
(2)向上取整,有小数就整数部分加1
js: Math.ceil(7/2)
(3)四舍五入.
js: Math.round(7/2)
(4)向下取整
js: Math.floor(7/2)
2、保留小数位数
Num.toFixed(weishu);如Num=1.2345 Num.toFixed(2)=1.23。
3、取模(余数)
i%x
0%4 =0,1%4=1,2%4=2,3%4=3,4%4=0,5%4=1
二、标签样式
1、hr水平线
<style type="text/css">
<!--
.hr0{ height:1px;border:none;border-top:1px dashed #0066CC;}
.hr1{ height:1px;border:none;border-top:1px solid #555555;}
.hr2{ height:3px;border:none;border-top:3px double red;}
.hr3{ height:5px;border:none;border-top:5px ridge green;}
.hr4{ height:10px;border:none;border-top:10px groove skyblue;}
-->
</style>
<hr class="hr0" />
<hr class="hr1" />
<hr class="hr2" />
<hr class="hr3" />
<hr class="hr4" />
三、事件类
1、阻止浏览器右键菜单
document.oncontextmenu = function ()
{
return false
}
2、阻止浏览器默认事件
//屏蔽浏览器默认事件
function stopDefault( e ) {
//阻止默认浏览器动作(W3C)
if ( e && e.preventDefault ) {
e.preventDefault();
}
else
window.event.returnValue = false;
return false;
}
3、div背景透明 IE事件监听无效的解决办法
background-image: url("data:image/gif; base64,AAAA");
四、调试
1、console.log(count)//控制台输出,调试程序,不打断程序
附:
1、鼠标样式
5、typeof 运算符
返回一个用来表示表达式的数据类型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
如:
alert(typeof (123));//typeof(123)返回"number"
alert(typeof ("123"));//typeof("123")返回"string"