jquery清空表單數(shù)據(jù)示例分享
更新時間:2014年02月13日 09:45:42 作者:
這篇文章主要介紹了jquery清空表單數(shù)據(jù)的示例,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
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;
});
};
您可能感興趣的文章:
相關(guān)文章
jQuery選擇器簡明總結(jié)(含用法實例,一目了然)
jQuery 選擇器一直是 jquery 最神秘,最強大的一部分,當然也是整個 jquery 里面非?;A(chǔ)的2014-04-04jquery實現(xiàn)的3D旋轉(zhuǎn)木馬特效代碼分享
這篇文章主要介紹了jquery實現(xiàn)的3D旋轉(zhuǎn)木馬特效,功能實現(xiàn)非常簡單,推薦給大家,有需要的小伙伴可以參考下。2015-08-08jQuery獲取所有父級元素及同級元素及子元素的方法(推薦)
這篇文章主要介紹了jQuery獲取所有父級元素及同級元素及子元素的方法,本文給大家介紹的非常詳細,具有參考借鑒價值 ,需要的朋友可以參考下2018-01-01