jquery.form.js用法之清空form的方法
本段代碼摘取自jquery.form.js中,由于覺得該方法的使用性非常強,同時也可獨立拿出來使用。
該段代碼言簡意賅可以很好的作為學習參考。
/**
* 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表示設置上下文環(huán)境,有多個表單時只作用調(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框架實現(xiàn)文件上傳功能案例解析(springmvc)
- 使用jQuery.form.js/springmvc框架實現(xiàn)文件上傳功能
- Struts2+jquery.form.js實現(xiàn)圖片與文件上傳的方法
- 使用jquery.form.js實現(xiàn)圖片上傳的方法
- jQuery插件之jQuery.Form.js用法實例分析(附demo示例源碼)
- 基于jQuery通過jQuery.form.js插件實現(xiàn)異步上傳
- jquery.form.js實現(xiàn)將form提交轉(zhuǎn)為ajax方式提交的方法
- 解決3.01版的jquery.form.js中文亂碼問題的解決方法
- jQuery.form.js的使用詳解
相關(guān)文章
jquery實現(xiàn)文字單行橫移或翻轉(zhuǎn)(上下、左右跳轉(zhuǎn))
本文詳細介紹了jquery實現(xiàn)單行橫移或翻轉(zhuǎn)(上下、左右跳轉(zhuǎn))的方法。具有一定的參考價值,下面跟著小編一起來看下吧2017-01-01從JavaScript 到 JQuery (1)學習小結(jié)
本人使用JavaScript 已經(jīng)有2年左右的時間了,一直被它簡潔優(yōu)雅的代碼所吸引, 近期接觸了 JQuery這個庫 , 感覺還不錯, 但是并不意味著要舍棄 JavaScript , 而是更宣揚結(jié)合使用 .2009-02-02jQuery+css實現(xiàn)的時鐘效果(兼容各瀏覽器)
這篇文章主要介紹了jQuery+css實現(xiàn)的時鐘效果,使用js的setTimeout方法實時修改頁面元素,實現(xiàn)動態(tài)顯示時鐘的功能.該代碼可兼容各瀏覽器,需要的朋友可以參考下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判斷一個元素是否含有一個指定的類(class)實例
下面小編就為大家?guī)硪黄褂胘query判斷一個元素是否含有一個指定的類(class)實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02