jquery清空表单数据示例分享_Javascript教程-查字典教程网
jquery清空表单数据示例分享
jquery清空表单数据示例分享
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下: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;

});

};

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类