手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jquery清空表单数据示例分享
jquery清空表单数据示例分享
摘要:复制代码代码如下:functionclearForm(form){//iterateoveralloftheinputsfortheform...

复制代码 代码如下:

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;

});

};

【jquery清空表单数据示例分享】相关文章:

jquery 构造函数在表单提交过程中修改数据

jQuery聚合函数实例

多种js图片预加载实现方式分享

显示行号的文本输入框

jquery滚动特效集锦

JQuery中DOM事件合成用法实例分析

jQuery构造函数init参数分析续

7个有用的jQuery代码片段分享

jquery中添加属性和删除属性

浅谈jQuery构造函数分析

精品推荐
分类导航