手机
当前位置:查字典教程网 >编程开发 >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构造函数init参数分析续

js实现键盘Enter键提交表单的方法

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

jQuery实现在列表的首行添加数据

js实现简单div拖拽功能实例

JQUERY表单暂存功能插件分享

jQuery聚合函数实例

jQuery插件制作之参数用法实例分析

javascript带回调函数的异步脚本载入方法实例分析

浅谈jQuery构造函数分析

精品推荐
分类导航