使用Jquery实现清除表单数据,功能点类似Button按钮的reset功能。
方法一:
<script type="text/javascript">
function clearFormData(objE){
if(!confirm("将清空表单数据,是否继续?")){
return;
}
$(objE).find(':input').each(
function(){
switch(this.type){
case 'text':
$(this).val('');
break;
case 'select-one':
$(this).val('');
break;
case 'password':
$(this).val('');
break;
}
}
);
}
</script>
其中,type="text"时,是指文本框;type="select-one"时,是指下拉框;type="password"时,是指密码框。
当然,文本域、单选按钮、多选框等这些都是支持de 。
方法二:
$(':input', '#myform').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
大家可以尝试一下!
本文介绍如何使用jQuery实现表单数据清除功能,包括文本框、下拉框、密码框等多种元素的支持。
934

被折叠的 条评论
为什么被折叠?



