|
第三页:控制文字域的值 (
)
将鼠标滑过该链接看看会发式什么事情。
通过改变文字域的值就可实现这种奇妙的变换。
改变文字域的链接为:
<a href="#"
onMouseOver="window.document.
first_form.first_text.value='Clap clap!';">
Yes, and I know it.</a>
<a href="#"
onMouseOver="window.document.
first_form.first_text.value='Sour puss!';">
No!</a>
意思是说,表单调用第1个表单,并将其值设为 'Clap clap!'第2行作用相似。这同改变图象的src非常相似。只不过文字域改变的是值。
对textareas也可以采用类似的方法改变值:
表单编码:
<form name="form_two">
<textarea name="the_textarea" rows=10 cols=60>
Mouse over below to see the first verse of
The Webmonkey song, adapted from
"I Wanna Be Like You" (The Monkey Song)
from Walt Disney's The Jungle Book
written by Richard M. Sherman and Robert
B. Sherman
</textarea>
</form>
注意该表单有一个名字:form_two,,并且文字区也有一个名字:the_textarea。
其链接和文字域的设定方法基本相同:
<a href="#"
onMouseOver="window.document.form_two.
the_textarea.value=first_part;">
Part 1</a>
<a href="#"
onMouseOver="window.document.form_two.
the_textarea.value=second_part;">
Part 2</a>
唯一的不同之处在于将一个变量赋值给textareas,而不是将字符串赋值给它。该变量在HTML首部已经做了定义。
以下是变量的字符串赋值:
var first_part = "Now I'm the king of the
swingers\nOh, the jungle VIP\nI've reached
the top and had to stop\nAnd
that's what botherin' me";
注意"\n"是换行符。如果你在一个<pre> 并且或在一个
textarea中写字,"\n" 换行符非常方便。
除了改变表单元素的值,JavaScript还可以让你检测在表单中进行的事件。
<a href="#"
onMouseOver="window.document.form_two.
the_textarea.value=first_part;">
Part 1</a>
<a href="#"
onMouseOver="window.document.form_two.
the_textarea.value=second_part;">
Part 2</a>
唯一的不同之处在于将一个变量赋值给textareas,
而不是将字符串赋值给它。该变量在HTML首部已经做
了定义。以下是变量的字符串赋值:
var first_part = "Now I'm the king of the
swingers\nOh, the jungle VIP\nI've reached
the top and had to stop\nAnd
that's what botherin' me";
注意"\n"是换行符。如果你在一个<pre> 并且或在一个 textarea中写字,"\n"
换行符非常方便。除了改变表单元素的值,JavaScript还可以让你检测在 表单中进行的事件。>>
JavaScript教程
第一页 第五课课程介绍
第二页 介绍反馈表单
第三页 控制文字域的值
第四页 文字域事件
第五页 反馈表单处理器
第六页 文字域的练习
第七页 复选框
第八页 单选框
第九页 选单
第十页 在选单中应用onchange命令
|