jquery.form.js用法之清空form的方法
本段代碼摘取自jquery.form.js中,由于覺得該方法的使用性非常強(qiáng),同時(shí)也可獨(dú)立拿出來使用。
該段代碼言簡(jiǎn)意賅可以很好的作為學(xué)習(xí)參考。
/**
* Clears the form data. Takes the following actions on the form's input fields:
* - input text fields will have their 'value' property set to the empty string
* - select elements will have their 'selectedIndex' property set to -1
* - checkbox and radio inputs will have their 'checked' property set to false
* - inputs of type submit, button, reset, and hidden will *not* be effected
* - button elements will *not* be effected
*/
$.fn.clearForm = function(includeHidden) {
return this.each(function() {
$('input,select,textarea', this).clearFields(includeHidden); //this表示設(shè)置上下文環(huán)境,有多個(gè)表單時(shí)只作用調(diào)用的表單
});
};
$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
return this.each(function() {
var t = this.type, tag = this.tagName.toLowerCase();
if (re.test(t) || tag == 'textarea') {
this.value = '';
}
else if (t == 'checkbox' || t == 'radio') {
this.checked = false;
}
else if (tag == 'select') {
this.selectedIndex = -1;
}
else if (t == "file") {
if (/MSIE/.test(navigator.userAgent)) {
$(this).replaceWith($(this).clone(true));
} else {
$(this).val('');
}
}
else if (includeHidden) {
// includeHidden can be the value true, or it can be a selector string
// indicating a special test; for example:
// $('#myForm').clearForm('.special:hidden')
// the above would clean hidden inputs that have the class of 'special'
if ( (includeHidden === true && /hidden/.test(t)) ||
(typeof includeHidden == 'string' && $(this).is(includeHidden)) ) {
this.value = '';
}
}
});
};
- jquery.form.js框架實(shí)現(xiàn)文件上傳功能案例解析(springmvc)
- 使用jQuery.form.js/springmvc框架實(shí)現(xiàn)文件上傳功能
- Struts2+jquery.form.js實(shí)現(xiàn)圖片與文件上傳的方法
- 使用jquery.form.js實(shí)現(xiàn)圖片上傳的方法
- jQuery插件之jQuery.Form.js用法實(shí)例分析(附demo示例源碼)
- 基于jQuery通過jQuery.form.js插件實(shí)現(xiàn)異步上傳
- jquery.form.js實(shí)現(xiàn)將form提交轉(zhuǎn)為ajax方式提交的方法
- 解決3.01版的jquery.form.js中文亂碼問題的解決方法
- jQuery.form.js的使用詳解
相關(guān)文章
表頭固定(利用jquery實(shí)現(xiàn)原理介紹)
表頭固定應(yīng)該是一個(gè)用得比較多的功能,參考了網(wǎng)上幾個(gè)例子,在幾個(gè)常用瀏覽器下顯示不是很完美2012-11-11jquery實(shí)現(xiàn)文字單行橫移或翻轉(zhuǎn)(上下、左右跳轉(zhuǎn))
本文詳細(xì)介紹了jquery實(shí)現(xiàn)單行橫移或翻轉(zhuǎn)(上下、左右跳轉(zhuǎn))的方法。具有一定的參考價(jià)值,下面跟著小編一起來看下吧2017-01-01從JavaScript 到 JQuery (1)學(xué)習(xí)小結(jié)
本人使用JavaScript 已經(jīng)有2年左右的時(shí)間了,一直被它簡(jiǎn)潔優(yōu)雅的代碼所吸引, 近期接觸了 JQuery這個(gè)庫 , 感覺還不錯(cuò), 但是并不意味著要舍棄 JavaScript , 而是更宣揚(yáng)結(jié)合使用 .2009-02-02jQuery+css實(shí)現(xiàn)的時(shí)鐘效果(兼容各瀏覽器)
這篇文章主要介紹了jQuery+css實(shí)現(xiàn)的時(shí)鐘效果,使用js的setTimeout方法實(shí)時(shí)修改頁面元素,實(shí)現(xiàn)動(dòng)態(tài)顯示時(shí)鐘的功能.該代碼可兼容各瀏覽器,需要的朋友可以參考下2016-01-01jQuery-1.9.1源碼分析系列(十)事件系統(tǒng)之事件體系結(jié)構(gòu)
這篇文章主要介紹了jQuery-1.9.1源碼分析系列(十)事件系統(tǒng)之事件體系結(jié)構(gòu)的相關(guān)資料,需要的朋友可以參考下2015-11-11使用jquery判斷一個(gè)元素是否含有一個(gè)指定的類(class)實(shí)例
下面小編就為大家?guī)硪黄褂胘query判斷一個(gè)元素是否含有一個(gè)指定的類(class)實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02jQuery UI Autocomplete 體驗(yàn)分享
jQuery UI Autocomplete是jQuery UI的自動(dòng)完成組件,是我用過的最強(qiáng)大、最靈活的Autocomplete,它支持本地的Array/JSON數(shù)組、通過ajax請(qǐng)求的Array/JSON數(shù)組、JSONP、以及Function(最靈活)等方式來獲取數(shù)據(jù)2012-02-02