---
title: "js常用函数整理 "
author: "dhl004"
date: "2012-03-22T15:47:48Z"
tags: ["JavaScript"]
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2012-03-22T15:47:48Z"
id: 1461477
url: "https://dhl004.iteye.com/blog/1461477"
---

(转)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(,&lt;标题&gt;,&lt;属性&gt;) window.open("","",""); 2、 回复：js常用函数整理~~~~ 控制横向和纵向滚动条的显隐？ 去掉x轴 去掉y轴 不显 -------------------------------------------------------------------------------- 表格变色 -------------------------------------------------------------------------------- 禁止复制，鼠标拖动选取 -------------------------------------------------------------------------------- 普通iframe页面 -------------------------------------------------------------------------------- iframe自适应高度 -------------------------------------------------------------------------------- IE地址栏前换成自己的图标&可以在收藏夹中显示出你的图标 -------------------------------------------------------------------------------- 字号缩放 越来越多的人长时间的泡网，眼镜的普及率也越来越高，让文字大点，让更多的用户看的更清楚。 需要指定大小的文字 [大](javascript:doZoom%2816%29) [中](javascript:doZoom%2814%29) [小](javascript:doZoom%2812%29) -------------------------------------------------------------------------------- select挡住div的解决方法 在div里加入下面的代码，根据需要调整就可以了。 -------------------------------------------------------------------------------- iframe(嵌入式帧)自适应高度 填写的嵌入地址一定要和本页面在同一个站点上，否则会提示“拒绝访问！”。对跨域引用有权限问题，请查阅其他资料。 -------------------------------------------------------------------------------- 跳转菜单新窗口 Internet Explorer Microsoft Home Developer Network -------------------------------------------------------------------------------- flash透明选项  -------------------------------------------------------------------------------- 添加到收藏夹和设为首页 添加到收藏夹： [添加到收藏夹](javascript:window.external.addFavorite%28'http://链接','说明'%29;) 设为首页： [设为首页](#) -------------------------------------------------------------------------------- 记录并显示网页的最后修改时间 -------------------------------------------------------------------------------- 节日倒计时 -------------------------------------------------------------------------------- 加在HEAD里 禁止缓存 -------------------------------------------------------------------------------- 让IFRAME框架内的文档的背景透明 -------------------------------------------------------------------------------- 打开窗口即最大化 -------------------------------------------------------------------------------- 加入背景音乐 只适用于IE  对Netscape ,IE 都适用 -------------------------------------------------------------------------------- 滚动 滚动信息 -------------------------------------------------------------------------------- 防止点击空链接时，页面往往重置到页首端 代码“javascript:void(null)”代替原来的“#”标记 -------------------------------------------------------------------------------- 文字或图片弹出指定大小的窗口 在body中加入 弹出代码 [图片或文字](#) -------------------------------------------------------------------------------- flash按钮加链接 on (press) { getURL("http://www.makewing.com","\_blank"); } -------------------------------------------------------------------------------- 跳转页面代码 -------------------------------------------------------------------------------- 细线分隔线

* * *

-------------------------------------------------------------------------------- 网页中的自动换行 就搞定了。 完整的是 style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word" -------------------------------------------------------------------------------- 消除ie6自动出现的图像工具栏，设置 GALLERYIMG属性为false或no . ![](mypicture.jpg) -------------------------------------------------------------------------------- 禁止页面正文内容被选取 -------------------------------------------------------------------------------- 不能点右键，不用CTRL+A，不能复制作! -------------------------------------------------------------------------------- IE浏览器支持一个 Body 属性 bgproperties，它可以让背景不滚动: -------------------------------------------------------------------------------- 随机变换背景图象（一个可以刷新心情的特效） -------------------------------------------------------------------------------- flash载入影片 on (release) { loadMovie("1-01.swf", "\_root.loaderclip"); } -------------------------------------------------------------------------------- 图片表单按钮

![](login.gif)

-------------------------------------------------------------------------------- 左右阴影背景的CSS定义方法 body { text-align:center; background-repeat: repeat-y; background-position: center; background-image: url(../images/bg.jpg); }