Posted on 2007-01-09 16:55
路易 阅读(274)
评论(0) 编辑 收藏 所属分类:
JavaScript
<
html
>
<
head
>
<
title
>
Test Page
</
title
>
<
script
src
="prototype.js"
></
script
>
<
script
>
function
test1()
{
var
d
=
$('myDiv');
//
$()类似于DOM中的document。getElementById()方法,根据传入的参数ID返回那个ID的元素
alert(d.innerHTML);
}
function
test2()
{
var
divs
=
$('myDiv','myOtherDiv');
for
(i
=
0
;i
<
divs.length;i
++
)
{
alert(divs[i].innerHTML);
//
将有i个弹出对话框
}
}
function
test3()
{
alert( $F('test3') );
//
$F() 根据网页中元素的ID来得到该元素的值,也可以传入元素本身作为参数
}
</
script
>
</
head
>
<
body
>
<
div
id
= "myDiv"
>
<
P
>
this is a paragraph
</
p
>
</
div
>
<
div
id
="myOtherDiv"
>
<
p
>
this is another paragraph
</
p
>
</
div
>
<
input
type
="button"
value
="Test1"
onclick
="test1();"
><
br
>
<
input
type
= "button"
value
="Test2"
onclick
="test2();"
><
br
>
<
input
type
="text"
value
= "louie"
id
= "test3"
><
br
>
<
input
type
= "button"
value
="Test3"
onclick
="test3();"
><
br
>
</
body
>
</
html
>