简要咨询咨询QQ网站导航网站搜索手机站点联系我们设为首页加入收藏 

jQuery清空表单的数据

来源:易贤网   阅读:3787 次  日期:2015-04-17 11:27:31

温馨提示:易贤网小编为您整理了“jQuery清空表单的数据”,方便广大网友查阅!

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;

});

};

更多信息请查看IT技术专栏

更多信息请查看脚本栏目
点此处就本文及相关问题在本站进行非正式的简要咨询(便捷快速)】     【点此处查询各地各类考试咨询QQ号码及交流群
上一篇:JavaScript操作时间的函数大全
下一篇:jQuery实现滑动返回页面顶部
易贤网手机网站地址:jQuery清空表单的数据
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!