jquery清空表单数据示例分享 - Web前端
作者:98wpeu发布时间:2026-06-13分类:网页前端技术浏览:3
复制代码 代码如下:
function clearFORM(form) {
// iterate over all of the inputs for the Form
// element that was passed in
$(':input', form).each(function() {
vartype = this.type;
var tag = this.tagName.toLowerCase(); // normalize case
// it's ok to reset the valueattr of text inputs,
// password inputs, and Textareas
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = "";
// checkboxes and radios need to have their checked state cleared
// but should *not* have their 'value' changed
else if (type == 'Checkbox' || type == 'radio')
this.checked = false;
// select elements need to have their 'selectedIndex' property set to -1
// (this works for both single and multiple select elements)
else if (tag == 'select')
this.selectedIndex = -1;
});
};
相关推荐
- jquery选择器之属性过滤选择器详解 - Web前端
- JQuery的Ajax请求实现局部刷新的简单实例 - Web前端
- jquery each的几种常用的使用方法示例 - Web前端
- jquery 图片缩放拖动的简单实例 - Web前端
- 使用JQuery快速实现Tab的AJAX动态载入(实例讲解) - Web前端
- jquery全选checkBox功能实现代码(取消全选功能) - Web前端
- jquery将一个表单序列化为一个对象的方法 - Web前端
- jquery遍历之parent()和parents()的区别及parentsUntil()方法详解 - Web前端
- jQuery向上遍历DOM树之parents(),parent(),closest()之间的区别 - Web前端
- jquery和ajax的关系详细介绍 - Web前端
- 网页前端技术排行
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


