javascript 学习笔记
2009-09-27 21:55
429 查看
(1)引入外部js文件:
<scriptsrc=”my.js”/>好像是这样呵呵,。
每个函数都默认有一个arguments对象来代表所有参数。
<scripttype="text/javascript">
functionadd(){
varout=0;
for(vari=0;i<arguments.length;i++){
out+=arguments[i];
}
returnout;}
</script>
<buttononclick="add(1,2,3,4,5)">Test</button>
(2)点击连接之后调用js代码
<ahref="javascript:addContact();">AddaContact</a>
点击图片之后改变图片
<imgsrc="button_off.gif"onmousedown="this.src='button_over.gif';"> onmousedown也可以为onmousedownonmouseoutonmouseup
点击按钮之后调用js
<buttononclick="doAction(multiply)">TestMultiply</button>
下面一段js代码说明了几个函数(功能是通过js新建一个按钮并带有各种属性)
<scripttype="text/javascript">
varboard=document.getElementById("board");//获得id号为board的元素,为div vare4=document.createElement("input");//创建一个input即<input> [b]e4.setAttribute("type","text");[/b]
//设置e4的type属性为text,即文本框这一句等于e.type=”text” e4.setAttribute("name","q");//设置input的Name属性为q e4.setAttribute("value","使用setAttribute");//input的初始值
e4.setAttribute("onclick","javascript:alert('Thisisatest!');");//设置点击事件 varobject=board.appendChild(e4);//将我们准备好的input放到<div>后面 </script>
<body><divid=board>
这句代码就等于<divid=board><inputname=qonclick=javascript:alert('Thisisatest!');>
最后来段简单的巩固一下,没啥好说的。
varimg=document.createElement('IMG');
img.setAttribute('src','delete.gif');
img.onclick=function(){
removeContact(tr);
}
td1.appendChild(img);
(3)getElementsByTagName:返回一个数组,包含具有相同tag名的所有元素类似于getElementById
(4)
注意看清楚了,这段代码分为4个子节点,其中第二个子节点又分3个子节点对了,我们现在要通过Js来修改内容,具体代码为
childNodes[1].childNodes[0]对应的应该就是<ahref=”link.html”>
childNodes[1].childNodes[1]对应的就是alink
(5)
setTimeout("alert('"+text+"');",1000);1秒之后弹出警告框
setInterval("alert('"+text+"');",1000);每隔1秒弹出一次警告框
varnewpasge=window.open('page2.html','TestWindow','width=500,height=200,resizable=yes');打开新窗口,newpasge为新窗口
window.close();关闭自己
改变状态栏:window.status(“****”);
前进后退window.history.go(1);
(6)js中的类详解见http://www.cnitblog.com/CoffeeCat/archive/2009/07/08/40138.html
Javascript中的类实现
(7)document对象:
1:document.title="主页";修改网页标题
2:document.URL="1.html";直接在本网页中打开新网页。
3:网页中第一个有<imgsrc=”1.jpg”name=”myimg”/>
document.links[0]访问第一个<ahref=”1.html”>链接。
Document.images[0]或者document.image[“myimg”];代表第一个图片见上面
document.image[“myimg”].src
同理document.forms[0]或者document.forms[“myform1”];访问表单
4:document.write(“向网页中写入一段话”);
(8)location对象
location.href=“www.qq.com”;利用这种导航方式跳转页面,该页面会被放入历史页面中。
(9)navigator
navigator
(10)填充用户屏幕
Window.moveTo(0,0);
Window.resizeTo(screen.availWidth,screen.availHeight);//表示获取屏幕尺寸,将浏览器置于全屏
相关文章推荐
- javascript的基础学习笔记
- Pro JavaScript Techniques 学习笔记1
- Javascript开发常用脚本学习笔记---Update1
- Javascript 学习 笔记二
- Javascript 学习笔记2 —— 函数
- JavaScript之正则表达式学习笔记
- javaScript学习笔记(晋级)一
- javascript学习笔记(七)--DOM基础
- javascript学习笔记(二):定义函数、调用函数、参数、返回值、局部和全局变量
- javascript学习笔记之javascript core
- JavaScript学习笔记(四十三) 迭代器
- javaScript 学习笔记【终篇】
- Javascript学习笔记-----函数
- JavaScript学习笔记2:通过user-Agent获取浏览器和操作系统信息
- 【学习笔记】JavaScript(2013-10-03)
- javascript DOM 学习笔记
- Javascript学习笔记-02
- JavaScript学习笔记(一)基本概念及语法
- Javascript学习笔记之 对象篇(一) : 对象的使用和属性
- Javascript学习笔记之 对象篇(四) : for in 循环