js中getElementById的用法.doc
文本预览下载声明
getElementById 的用法:
顾明思义,get-Element-By-Id,就是通过ID来设置/返回HTML标签的属性及调用其事件与方法。用这个方法基本上可以控制页面所有标签,条件很简单就是给每个标签分配一个ID号返回具有指定 ID 属性值的第一个对象的一个引用。?语法?Element = document.getElementById(“”)
获得ID值=id的所有属性和方法?Js中经常使用它通过控件ID取得元素的值如一个form里包text、label等,他们都是FORM的元素,有一个分配的ID,getElementById()是取得这些元素的text值的。?
html
head
title
getElementById /title
script language = javascript
function change(){
document.getElementById(mr).innerHtml=;
document.getElementById(mr).href=http://123./;
}
/script
/head
body
a id=r href=/ 百度/a
form name=myform
input type=button value=更换连接 onClick=change() /
/form
/body
/html?!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN /TR/xhtml1/DTD/xhtml1-transitional.dtd
2、html xmlns=/1999/xhtml
head
meta http-equiv=Content-Type content=text/html; charset=gb2312 /
title无标题文档/title
script language=javascript
function reset(){
var divTest = document.getElementById(divTest);
divTest.innerHTML = 这是一个有感觉的标记;
}
function s(){
var divTest = document.getElementById(divTest);
divTest.innerHTML = 老鼠来了;
}
/script
/head
body
h1 id=divTest onmousemove=s() onmouseout=reset() align=center这是一个有感觉的标记/h1
/body
/html
3、!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN /TR/xhtml1/DTD/xhtml1-transitional.dtd
html xmlns=/1999/xhtml
head
meta http-equiv=Content-Type content=text/html; charset=gb2312 /
title无标题文档/title
script language=javascript
!--
var n=0;
function changefontcolor(){
n=n%4;
switch(n){
case 0:
main_title.color=red;
break;
case 1:
main_title.color=green;
break;
case 2:
main_title.color=blue;
break;
case 3:
main_title.color=yellow;
}
n++;
}//定时执行函数每秒钟调用changefontcolor()函数一次,改变大标题的颜色
setInterval(changefontcolor(),1000);
//--
/script
/head
font ID=main_title size=6b虚拟网络世界/b/font
body
/body
/html
4、!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN /TR/xhtml1/DTD/xhtml1-transitional.dtd
html
显示全部