231个常用JavaScript代码.docx

上传人:b****9 文档编号:25560367 上传时间:2023-06-09 格式:DOCX 页数:93 大小:50.56KB
下载 相关 举报
231个常用JavaScript代码.docx_第1页
第1页 / 共93页
231个常用JavaScript代码.docx_第2页
第2页 / 共93页
231个常用JavaScript代码.docx_第3页
第3页 / 共93页
231个常用JavaScript代码.docx_第4页
第4页 / 共93页
231个常用JavaScript代码.docx_第5页
第5页 / 共93页
点击查看更多>>
下载资源
资源描述

231个常用JavaScript代码.docx

《231个常用JavaScript代码.docx》由会员分享,可在线阅读,更多相关《231个常用JavaScript代码.docx(93页珍藏版)》请在冰豆网上搜索。

231个常用JavaScript代码.docx

231个常用JavaScript代码

事件源对象

event.srcElement.tagName

event.srcElement.type

捕获释放

event.srcElement.setCapture();

event.srcElement.releaseCapture();

事件按键

event.keyCode

event.shiftKey

event.altKey

event.ctrlKey

事件返回值

event.returnValue

鼠标位置

event.x

event.y

窗体活动元素

document.activeElement

绑定事件

document.captureEvents(Event.KEYDOWN);

访问窗体元素

document.all("txt").focus();

document.all("txt").select();

窗体命令

document.execCommand

窗体COOKIE

document.cookie

菜单事件

document.oncontextmenu

创建元素

document.createElement("SPAN");

根据鼠标获得元素:

document.elementFromPoint(event.x,event.y).tagName=="TD

document.elementFromPoint(event.x,event.y).appendChild(ms)

窗体图片

document.images[索引]

窗体事件绑定

document.onmousedown=scrollwindow;

元素

document.窗体.elements[索引]

对象绑定事件

document.all.xxx.detachEvent('onclick',a);

插件数目

navigator.plugins

取变量类型

typeof($js_libpath)=="undefined"

下拉框

下拉框.options[索引]

下拉框.options.length

查找对象

document.getElementsByName("r1");

document.getElementById(id);

定时

timer=setInterval('scrollwindow()',delay);

clearInterval(timer);

UNCODE编码

escape(),unescape

父对象

obj.parentElement(dhtml)

obj.parentNode(dom)

交换表的行

TableID.moveRow(2,1)

替换CSS

document.all.csss.href="a.css";

并排显示

display:

inline

隐藏焦点

hidefocus=true

根据宽度换行

style="word-break:

break-all"

自动刷新

简单邮件

aaa@?

subject=ccc&body=xxxyyy">

快速转到位置

obj.scrollIntoView(true)

anchors

网页传递参数

location.search();

可编辑

obj.contenteditable=true

执行菜单命令

obj.execCommand

双字节字符

/[^\x00-\xff]/

汉字

/[\u4e00-\u9fa5]/

让英文字符串超出表格宽度自动换行

word-wrap:

break-word;word-break:

break-all;

透明背景

获得style内容

obj.style.cssText

HTML标签

document.documentElement.innerHTML

第一个style标签

document.styleSheets[0]

style标签里的第一个样式

document.styleSheets[0].rules[0]

防止点击空链接时,页面往往重置到页首端。

word

上一网页源

asp:

request.servervariables("HTTP_REFERER")

BLOCKEDSCRIPT

document.referrer

释放内存

CollectGarbage();

禁止右键

document.oncontextmenu=function(){returnfalse;}

禁止保存

禁止选取

禁止粘贴

地址栏图标

favicon.ico名字最好不变16*16的16色,放虚拟目录根目录下

收藏栏图标

查看源码

'+'

关闭输入法

disabled">

自动全选

ENTER键可以让光标移到下一个输入框

文本框的默认值

title换行

obj.title="123 sdfs "

获得时间所代表的微秒

varn1=newDate("2004-10-10".replace(/-/g,"\/")).getTime()

窗口是否关闭

win.closed

checkbox扁平

absolute;clip:

rect(5px15px15px5px)">

获取选中内容

document.selection.createRange().duplicate().text

自动完成功能

打开该功能

关闭该功能

窗口最大化

无关闭按钮IE

window.open("aa.htm","meizz","fullscreen=7");

统一编码/解码

alert(decodeURIComponent(encodeURIComponent("http:

//你好.com?

as=hehe")))

encodeURIComponent对":

"、"/"、";"和"?

"也编码

表格行指示

管理员

发帖

1768

•加关注

•发消息

只看该作者沙发发表于:

2008-08-14

1.文本框焦点问题

onBlur:

当失去输入焦点后产生该事件

onFocus:

当输入获得焦点后,产生该文件

Onchange:

当文字值改变时,产生该事件

Onselect:

当文字加亮后,产生该文件

(value==''){value='郭强'}">点击时文字消失,失去焦点时文字再出现

 

2.网页按钮的特殊颜色

style="background-color:

rgb(235,207,22)">

3.鼠标移入移出时颜色变化

onMouseOver=this.style.color="red"class="button">

4.平面按钮

1pxsolid:

#666666;height:

17px;width:

25pt;font-size:

9pt;

BACKGROUND-COLOR:

#E8E8FF;color:

#666666"name="submit">

5.按钮颜色变化

1pxsolid#666666;font-size:

9pt;height:

17px;

BACKGROUND-COLOR:

#F4F4FF;color:

#ff6600"size="15"maxlength="16">

6.平面输入框

solid;border-width:

1">

7.使窗口变成指定的大小

8.使文字上下滚动

height=60>

--head_scrolltext-->

共和国

--endhead_scrolltext-->

9.状态栏显示该页状态

10.可以点击文字实现radio选项的选定


情侣:

一次注册两个帐户

11.可以在文字域的font写onclick事件

12.打印打印网页

window.print()'>

13.线型输入框

class="line">

14.显示文档最后修改日期

functionhi(str)

{

document.write(document.lastModified)

alert("hi"+str+"!

")

}

15.可以在鼠标移到文字上时就触发事件

--Hiding

functionhello(){

alert("哈罗!

");

}

link

16.可以根据网页上的选项来确定页面颜色

background.html

Arial">

ChangingBackgroundColors


17.将按钮的特征改变

--

.style1{font-size:

12px;background:

#CCCCFF;border-width:

thinthinthinthin;border-color:

#CCCCFF

#CCCCCC#CCCCCC#CCCCFF}

.style2{font-size:

12px;font-weight:

bold;background:

#CCFFCC;border-width:

thinmediummediumthin;

border-color:

#CCFF99#999999#999999#CCFF99}

-->

  本例按钮的代码如下:

onmouseout="this.className='style1'"class="style1">

18.改变按钮的图片.

--

.style3{font-size:

12px;background:

url(image/buttonbg1.gif);border:

0px;width:

60px;height:

22px}

.style4{font-size:

12px;font-weight:

bold;background:

url(image/buttonbg2.gif);border:

0px0;width:

60px;height:

22px}

-->

  本例的按钮代码如下:

onmouseout="this.className='style3'"class="style3">

19.打印页面

doPrint();">打印本稿

20.可以直接写html语言

document.write("");

21.改变下拉框的颜色

onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)"

size="1"style="color:

#008080;font-size:

9pt">

22.转至目标URL

window.location="http:

//guoguo"

23.传递该object的form

UpdateSN('guoqiang99267',this.form)

functionUpdateSN(strValue,strForm)

{

strForm.SignInName.value=strValue;

returnfalse;

}

24.文字标签

>guoqiang99859

25.layer2为组件的ID,可以控制组件是否可见

document.all.item('Layer2').style.display="block";

document.all.item('Layer2').style.display="none";//

26.将页面加入favorite中

--

functionAddme(){

url="http:

//your.site.address";//你自己的主页地址

title="YourSiteName";//你自己的主页名称

window.external.AddFavorite(url,title);

-->

//

27.过10秒自动关闭页面

functioncloseit(){

setTimeout("self.close()",10000)

}

28.可以比较字符的大小

char=post.charAt(i);

if(!

('0'<=char&&char<='9'))

29.将字符转化为数字

month=parseInt(char)

30.点击value非空的选项时转向指定连接

="")window.open(this.value)'class="textinput">

主办单位

31.改变背景颜色

onmouseout="this.bgColor='#FAFBFC';">

32.改变文字输入框的背景颜色

33.改变水平线的特征

34.传递参数的方式

CurPage=8&id=3488">8

35.页内跳转

1

2

3

4

5

6

7

dfdf

dfdf//

36.两个按键一起按下

if(event.ctrlKey&&window.event.keyCode==13)//

37.刷新页面

javascript:

this.location.reload()//

38.将网页的按钮使能

functionhaha()

{

f

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1