使用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');
大家可以尝试一下!