使用Prototype的一点心得体会(四)
2008-05-22 13:19
567 查看
使用Field对象操作表单域 ( API: http://www.prototypejs.org/api/form )
示例代码:
<html>
<head>
<script src="prototype-1.6.0.2.js" type="text/javascript"></script>
</head>
<body>
<input id="text1" type="text" /><br>
<input id="text2" type="text" /><br>
<input id="text3" type="text" /><br>
<input id="text4" type="text" value="xxxxxxxxx"/><br>
<select size="3" id="st1">
<option>Java</option>
<option>Struts</option>
<option>Spring</option>
</select>
<br>
<input type="button" value="aa" onClick="Field.clear('text1','text2','text3')"/><br>
<input type="button" value="bb" onClick="alert(Field.present('text1','text2','text3'))"/><br>
<input type="button" value="cc" onClick="Field.focus('text3')"/><br>
<input type="button" value="dd" onClick="Field.select('text4')"/><br>
<input type="button" value="ee" onClick="Field.activate('st1')"/><br>
</body>
<script>
</script>
函数介绍:
1.clear : 清除传入该方法的所有表单域得值。
2.present : 判断所有表单域是否都有值。
3.focus : 指定焦点。
4.select : 选中表单域内的文本(只对文本框,文本有效)。
5.activate : 同select,并额外多一个功能:如果目标元素是不可选中的,则焦点移动到目标元素。
此外,还可以使用Form.Element对象,示例代码如下:
<html>
<head>
<script src="prototype-1.6.0.2.js" type="text/javascript"></script>
</head>
<body>
<input id="text1" name="text1" type="text" /><br>
<input type="button" value="aaa" onClick="alert(Form.Element.serialize('text1'));"/><br>
<input type="button" value="bbb" onClick="alert(Form.Element.getValue('text1'));"/><br>
</body>
</html>
示例代码:
<html>
<head>
<script src="prototype-1.6.0.2.js" type="text/javascript"></script>
</head>
<body>
<input id="text1" type="text" /><br>
<input id="text2" type="text" /><br>
<input id="text3" type="text" /><br>
<input id="text4" type="text" value="xxxxxxxxx"/><br>
<select size="3" id="st1">
<option>Java</option>
<option>Struts</option>
<option>Spring</option>
</select>
<br>
<input type="button" value="aa" onClick="Field.clear('text1','text2','text3')"/><br>
<input type="button" value="bb" onClick="alert(Field.present('text1','text2','text3'))"/><br>
<input type="button" value="cc" onClick="Field.focus('text3')"/><br>
<input type="button" value="dd" onClick="Field.select('text4')"/><br>
<input type="button" value="ee" onClick="Field.activate('st1')"/><br>
</body>
<script>
</script>
函数介绍:
1.clear : 清除传入该方法的所有表单域得值。
2.present : 判断所有表单域是否都有值。
3.focus : 指定焦点。
4.select : 选中表单域内的文本(只对文本框,文本有效)。
5.activate : 同select,并额外多一个功能:如果目标元素是不可选中的,则焦点移动到目标元素。
此外,还可以使用Form.Element对象,示例代码如下:
<html>
<head>
<script src="prototype-1.6.0.2.js" type="text/javascript"></script>
</head>
<body>
<input id="text1" name="text1" type="text" /><br>
<input type="button" value="aaa" onClick="alert(Form.Element.serialize('text1'));"/><br>
<input type="button" value="bbb" onClick="alert(Form.Element.getValue('text1'));"/><br>
</body>
</html>
相关文章推荐
- 使用Prototype的一点心得体会(二)
- 使用Prototype的一点心得体会(六)
- 使用Prototype的一点心得体会(一)
- 使用Prototype的一点心得体会(五)
- 使用Prototype的一点心得体会(三)
- 使用Spring Boot Gradle 打war包的一点心得体会
- 对于scanf的使用一点体会心得
- 使用Spring Boot Gradle 打war包的一点心得体会
- 关于使用git的一点心得体会
- 使用Webbrowser的一点心得体会
- C#使用Webbrowser的一点心得体会
- C#使用Webbrowser的一点心得体会
- 使用Webbrowser的一点心得体会
- 使用Webbrowser的一点心得体会
- 关于配置环境变量的一点心得体会
- 在32位系统下使用MongoDB的一点心得
- 学习使用Borland Together心得体会(二)
- 我学习使用java的一点体会
- pyqt 学习基础 4 - creater的一点使用心得
- uboot使用之心得体会