日期:2014-05-16  浏览次数:20346 次

js常用函数整理
(转)js常用函数整理
类型判断:typeof;eg:if(typeof(var)!="undefined")\isNaN

字符处理函数:toLowerCase\touppercase\
substring(从哪里截到哪)\substr(从哪里开始;截多少个字符) \indexOf(字串中找某串字符)\replace(替换函数)\
charCodeAt
concat
split
join

定时处理函数:setInterval;setTimeout;clearTimeout;clearInterval

两个显示控制属性:visibility(hidden,hide,show,visible);display(none,block,inline)

编码的一些函数:escape();

取得对象的方法:
document.getElementsByTagName(根据标签名获得对象组)\
document.getElementsByTagName('head').item(0)
document.getElementsByName(通过NAME获得对象)\
document.getElementById(通过ID获得对象)\
document.form1.f1\
document.all.tags(t)[id]
document.all[id]
document.layers[id]

不常用的一些方法:
moveToAbsolute:
fromElement
toElement
contains
captureEvents
parent.frames
moveTo(x,y)
resizeBy(x,y)
resizeTo(x,y)
attachEvent('onmousedown',showHide);
document.createElement('')
document.createTextNode('')
obj.setAttribute('src','')
obj.getAttribute('')
event.srcElement
style.cssText
document.body.appendChild
document.body.removeChild
document.body.insertAdjacentHTML("AfterBegin",s)
innerHTML/
removeNode
insertBefore
arguments
event.keyCode

正则相关:RegExp(eg:new RegExp("\"","g"))

一些长宽及位置属性:
window.innerHeight
window.innerWidth
document.documentElement.clientWidth
document.documentElement.clientHeight
document.body.clientWidth
document.body.clientHeight
document.body.offsetWidth
document.body.offsetHeight
document.body.scrollLeft
document.body.scrollTop
document.location.reload()

window一些方法:
window.onerror=function(){return true;}隐去报错
window.onload\window.onunload
window.status
window.parent.location.href
window.location.href
window.top.location.href

数学方法:
Math.max


数组方法:
length
slice

JS输出方法:
document.write(s);
alert(s);
confirm
prompt
document.writeln
弹窗方法:
window.showModalDialog(<url>,<标题>,<属性>)
window.open("","","");


2、 回复:js常用函数整理~~~~
控制横向和纵向滚动条的显隐?
<body style="overflow-y:hidden"> 去掉x轴
<body style="overflow-x:hidden"> 去掉y轴
<body scroll="no">不显

--------------------------------------------
表格变色
<TD onmouseover="this.style.backgroundColor='#FFFFFF'"
onmouseout="this.style.backgroundColor=''"
style="CURSOR: hand">
--------------------------------------------
禁止复制,鼠标拖动选取
<body ondragstart=window.event.returnValue=false oncontextmenu=window.event.returnValue=false onselectstart=event.returnValue=false>
--------------------------------------------
普通iframe页面
<iframe name="name" src="main.htm" width="450" height="287" scrolling="Auto" frameborder="0"></iframe>

--------------------------------------------
iframe自适应高度
<iframe name="pindex" src="index.asp" frameborder=false scrolling="auto" width="100%" height="100%" frameborder=no onload="document.all['pindex'].style.height=pindex.document.body.scrollHeight" ></iframe>
--------------------------------------------
IE地址栏前换成自己的图标&可以在收藏夹中显示出你的图标
<link rel="Shortcut Icon" href="favicon.ico">
<link rel="Bookmark" href="favicon.ico">
--------------------------------------------
字号缩放
越来越多的人长时间的泡网,眼镜的普及率也越来越高,让文字大点,让更多的用户看的更清楚。
<script type="text/javascript">
function doZoom(size)
{document.getElementById('zoom').style.fontSize=size+'px';}
</script>
<span id="zoom">需要指定大小的文字</span>
<a href="javascript:doZoom(16)">大<