Javascript 操作表单域的两个重要技巧 By shawl.qiu
2006-10-29 19:10
597 查看
Javascript 操作表单域的两个重要技巧 By shawl.qiu
说明:技巧一:
当表单提交或重置时向客户端进行确认操作
技巧二:
列出表单域中所有元素及其重要属性, 就是 input, select 等的 name, value 等.
总结:
用这两个技巧可以写一个通用的客户端表单验证函数, 至于怎么写, 动动脑筋就行了^^.
但是鄙人还是觉得, 不能过于依赖客户端的验证机制, 现在的人聪明得很, 只要花一点小心思, 就可以避过客户端的一切限制, 鄙人就乐于此道.
目录:
1. 当表单提交或重置时向客户端进行确认操作
2. 列出表单域中所有元素及其重要属性
shawl.qiu
2006-10-29
http://blog.csdn.net/btbtd
目录:
1. 当表单提交或重置时向客户端进行确认操作
linenum
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function fCfm(msg){
if(confirm(msg))return true;
return false;
} // shawl.qiu script
//]]>
</script>
<form name="form1" id="form1" method="get" action=""
onsubmit="return fCfm('现在提交数据吗?');"
onreset="return fCfm('现在重置表单域所有内容吗?');" >
<input name="textfield" type="text" value="tbx default value" />
<br />
<textarea name="textarea">txa default value</textarea>
<br />
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Reset" />
</form><br />
<a href="?">back</a>
2. 列出表单域中所有元素及其重要属性
linenum
<script type="text/javascript">
//<![CDATA[
function fListFmEle(obj){
try{ w.close(); } catch(e){}
w=open('', 'popup', 'width=500, height=500, left=200, top=100, scrollbars')
w.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
for(var i=0; i<obj.length; i++){
w.document.write('obj name: ',obj[i].name.fontcolor('red'),
'<br/>obj type: ',obj[i].type.fontcolor('red'),
'<br/>obj.value: ', obj[i].value.fontcolor('blue'),
'<p/>');
}
w.document.onclick=function(){ w.close(); }
w.focus();
} // shawl.qiu script
//]]>
</script>
<a href="#" onclick="fListFmEle(document.fm);">list form elements</a><p/>
<form name="fm" id="fm" method="post" action="">
<input name="textfield" type="text" value="tbx value" /><br />
<input type="radio" name="RadioGroup1" value="radio" />Radio<br />
<input type="radio" name="RadioGroup1" value="radio" />Radio<br />
<input name="cbx" type="checkbox" id="cbx" value="checkbox" />
<input name="cbx1" type="checkbox" id="cbx1" value="checkbox" />
<input name="cbx2" type="checkbox" id="cbx2" value="checkbox" /><br />
<select name="select">
<option value="v">opt</option>
<option value="v1">opt1</option>
</select><br />
<select name="sle1" size="2" multiple id="sle1">
<option value="v">sle</option>
<option value="v1">sle1</option>
</select><br />
<textarea name="textarea">txa value</textarea><br />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
相关文章推荐
- Javascript 操作表单域的两个重要技巧
- Javascript 操作表单域的两个重要技巧
- Javascript 操作表单域的两个重要技巧
- Javascript 读写 Cookie 操作 By shawl.qiu
- Javascript url 解码算法(utf-8) by shawl.qiu
- Javascript 中模拟 Enum By shawl.qiu
- 重写与扩展 JScript/Javascript String 对象的 HTML 函数 By shawl.qiu
- Javascript 元素拖曳操作 By shawl.qiu (兼容IE,Opera,Firefox)
- 使用 javascript 函数 完美控制页面图片显示大小 By shawl.qiu
- javascript utf-8 url 编码 之 纯算法 解码 by shawl.qiu 2007-9-24
- Javascript 小工具, fCoper(按字串长短排序) By shawl.qiu
- Javascript 动态添加表格行(Tr),表格单元(Td) By shawl.qiu 2007-9-7
- 枚举 javascript 常用对象方法 By shawl.qiu
- 核心(Core) Javascript 学习手记 By shawl.qiu
- 玩转 Javascript 弹出窗口, 居中与居角扩大窗口至屏幕最大值 By shawl.qiu
- Javascript_ 只允许输入英文及其相关标点符号 By shawl.qiu
- Javascript 小工具, StringToArray(字串转数组) By shawl.qiu
- c# .net 编写 HTML 编辑器的核心技巧 by shawl.qiu
- 使用 javascript HTML DOM 高亮显示页面特定字词 By shawl.qiu
- 使用 js + button标签 模拟 select 列表框 操作 By shawl.qiu