展会信息港展会大全

jquery清空表单数据示例分享
来源:互联网   发布日期:2016-03-24 20:08:08   浏览:2849次  

导读:这篇文章主要介绍了jquery清空表单数据的示例,需要的朋友可以参考下代码如下:function clearForm(form) { // iterate over all of th...

这篇文章主要介绍了jquery清空表单数据的示例,需要的朋友可以参考下

代码如下:

function clearForm(form) {

// iterate over all of the inputs for the form

// element that was passed in

$(':input', form).each(function() {

var type = this.type;

var tag = this.tagName.toLowerCase(); // normalize case

// it's ok to reset the value attr 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;

});

};

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港