您的位置:寻梦网首页编程乐园JavaScriptJavascript入门到精通
Javascript 入门到精通

第 1 天 第 2 天 第 3 天 第 4 天 第 5 天
第 3 页:控制文字域的值
作者:Thau!
将鼠标滑过该链接看看会发式什么事情。

错误!超级链接引用无效。 错误!超级链接引用无效。

<form name="first_form">

<input type="text" name="first_text" value="Are you happy?">

</form>

改变文字域的链接为:

<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>
window.document.first_form.first_text.value='Clap clap!'
意思是说,表单调用第1个表单,并将其值设为 'Clap clap!'第
2行作用相似。这同改变图象的src非常相似。只不过文字域改变
的是值。

对textareas也可以采用类似的方法改变值:

错误!超级链接引用无效。 错误!超级链接引用无效。

<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还可以让你检
测在表单中进行的事件。

第1页:第5日课程介绍
第2页:介绍反馈表单
第3页:控制文字域的值
第4页:文字域事件
第5页:反馈表单处理器
第6页:文字域的练习
第7页:复选框
第8页:单选框
第9页:选单
第10页:在选单中应用onchange命令



通过改变文字域的值就可实现这种奇妙的变换。表单编码:

<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

其链接和文字域的设定方法基本相同:

本内容由搜狐网站(www.sohoo.com.cn)提供。