转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
事半功倍之Javascript(2)         ★★★★

事半功倍之Javascript(2)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:735 更新时间:2009/4/23 11:30:12

第五章 使用函数

1.声明函数

<script>
function quote()
{ document.write("输出语句")
}
</script>

2.调用函数

<script>
function quote()
{ document.write("输出语句")
}
quote()
</script>

3.了解全局变量和局部变量

任何不用 var关键字声明的变量都是全局变量,任何在函数外声明的变量都是全局变量

4.将参数传送给函数

<script>
function f(item)
{document.write("输出参数"+item+"<br>")
}
f("fgdfgd")
f("参数二")
</script>

5.从函数返回值

<script>
function average(var1,var2,var3)
{ave=(var1+var2+var3)/3;
document.write("输出结果");
return ave;
}
document.write(average(34,56,78))
</script>

6.通过HTML链接调用函数

<script>
function quote(){
document.write(" 输出字符串")
}
</script>
<a href=javascript:quote()>通过HTML链接调用函数</a>
<a href=javascript:Document.write("输出字符")> 通过HTML链接调用函数,直接写javascript语句</a>

第六章 处理事件

1.检查鼠标单击

<form name=form1>
<input type=button name=button1 value=hello onclick=document.form1.button1.value='there'>
</form>

2.检测双击

<form name=form1>
<input type=button name=button1 value=hello onclick=document.form1.button1.value='你单击了按钮' ondblclick=document.form1.button1.value='你双击了该按钮'>
</form>

3.创建悬停按钮

<img src=go.gif onmouseover=document.images[0].src='go2.gif' onmouseout= document.images[0].src='go.gif'>

4.检测按键

<form name=form1>
<input type=text name=text1 value=hello onkeypress="if(window.event.keyCode=='100') document.form1.text1.value='你按了d键'">
</form>

5.设置焦点

<form name=form1>
<input type=text name=text1 value=hello
onfous=document.form1.text1.value='该文本框获得焦点'
onblur=document.form1.text1.value='该文本框失去焦点'>
</form>

6.检测下拉菜单选择

<form name=form1>
<select name=select1 size=4
onChange=document.form1.text1.value=document.form1.select1.value>
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="武汉">武汉</option>
<option value="天津">天津</option>
<option value="大连">大连</option>
</select>
<input tppe=text name=text1 value=hello>
</form>

7.创建网页加载和卸载信息

<body onload=document.form1.text1.value='页面加载完毕' onunload=alert('再见,欢迎再来')>
<form name=form1>
<input type=text name=text1 value="页面正在加载 ……">
</form>

第七章 使用对象

1.理解对象\属性和方法

<body bgcolor="green">
<script>
document.write("页面背景颜色是:"+document.bgColor)
document.write("页面前景颜色是:"+document.fgColor)
</script>

2.使用网页元素对象

<script>
</script>
<form name=form1>
<textarea name=ta1>dfgfdgfdhfdhdfdfgdf</textarea>
<input type=button value="选择文本" onclick=document.form1.ta1.select()>
<input type=button value="显示文本" onclick=document.write(document.form1.ta1.value)>
</form>

3.使用子对象

<form name=form1>
<input type=text name=text1 value=hello>
</form>
<script>
document.form1.text1.value="gdfgfd"
</script>

<form name=form1>
<input type=radio name=radio1>男
<input type=radio name=radio2>女
</script>
<script>
document.form1.radio1.checked=true
</script>

4.使用预定义对象

<script>
str1="dgdfgdfgdfhf固定法固定法功夫攻打法"
document.write(str1+"<br>")
str2=str1.substr(5)
document.write(str2+"<br>")
document.write("输出圆的面积:"+Math.PI*Math.pow(5.0,2))
</script>

5.创建新对象

<script>
today=new Date()
document.write("今天是"+(today.getMonth()+1)+"月"+today.getDate()+"日"+"<br>")
document.write("现在是:"+today.toLocaleString())
</script>

6.引用当前对象

<form name=form1>
<input type=text name=text1 value="dgdgdfgfd" onclick=this.select()>
</script>

7.查看对象属性

<script>
for(prop in window)
{document.write("window."+prop+"="+window[prop]+"<br>");}
for(prop2 in location)
{document.write("location."+prop2+"="+location[prop]+"<br>");}
</script>

8.使用Array对象

<script>
array=new Array(10)
array[0]="bark"
array[1]="apple"
array[2]="nebula"
array[3]="cookie"
array[4]="technology"
document.write("数组元素个数是"+array.Length+"<br>")
document.write("用 join将数组合并"+array.join(" ")+"<br>")
document.write(" 数组排序"+array.sort())
</script>

9.使用 image 对象

<img src=**.gif alt="图片提示…." border=10>
<script>
document.write("图片提示是:"+document.images[0].alt+"<br>")
document.write("图片边框大小是:"+document.images[0].broder)
</script>

10.预加载图像

<script>
freddy=new Image()
freddy.src=freddy.gif
</script>
<body onload=document.images[0].src=freddy.src>
,<img src="blank.gif">
</body>

11.改变图像

<img src=freddy.gif><br>
<form name=form1>
<input type=button name=button1 value="改变图像" onclickd=document.images[0].src=dudjp.gif>
</form>

12.使用link和anchor对象

<a name=anchor1>锚点1<br>
<a href=http://www.microsoft.com>Microsoft</a><br>
<a href=http://www.sohu.com>sohu</a><br>
<a href=http://www.sina.com.cn>sina</a><br>
<script>
document.write("本页面共有"+document.links.length+"链接"+"<br>")
document.write("本页面共有"+document.anchors.length+"锚点"+"<br>")
document.write("第一个链接协议是"+document.links[0].protocol+"<br>")
document.write("第一个链接路径是"+document.links[0].pathnamel+"<br>")
document.write("第一个链接href是"+document.links[0].hrefl+"<br>")
</script>

13.改变链接

<a href =http://www.microsoft.com>link</a>
<form name=form1>
<input type=button name=button1 value="改变链接" onclick=document.links[0].href='http://www.sohu.com'>
</form>

14.使用history对象

<form name=form1>
<input type=button name=button1 value="向后返回2页" onclick=window.history.go(-2)>
</form>


[操作系统]Windows2000/XP/2003操作系统常见问题集锦下篇  [操作系统]Windows2000/XP/2003操作系统常见问题集锦上篇
[操作系统]WinXP/2000操作系统自动关机的实现  [操作系统]过河不拆桥—切勿忘记OS/2第二代操作系统之下篇
[操作系统]过河不拆桥—切勿忘记OS/2第二代操作系统之上篇  [系统软件]Visual Studio 2005 Express Editions Beta 2 下载…
[常用软件]IE 7出炉,Firefox 2当道.谁才是“王者”?  [常用软件]豪华的冲浪引擎MSN Explorer (2)
[VB.NET程序]VB.NET实现DirectDraw9 (2) 动画  [VB.NET程序]学习笔记,VB.NET使用DirectSound9 (2)
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台