您的位置:首页 > Web前端 > JavaScript

js常用函数整理

2012-11-30 09:25 561 查看
类型转换:parseInt\parseFloat\toString

类型判断: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("","","");

附:常用DOM方法和属性(即必须掌握部分)

创建节点:createElement();createTextNode()

复制节点:cloneNode()

插入节点:appendChild();insertBefore()

删除节点:removeChild()

替换节点:replaceChild()

设置节点属性:setAttribute()

查找节点:getAttribute();getElementById();getElementsByTagName();hasChildNodes

节点的属性:nodeName;nodeType;nodeValue

遍历节点树:childNodes;firstChild;lastChild;nextSibling;parentNode;previousSibling
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: