jquery.form.js用法之清空form的方法
本段代碼摘取自jquery.form.js中,由于覺得該方法的使用性非常強(qiáng),同時(shí)也可獨(dú)立拿出來使用。
該段代碼言簡意賅可以很好的作為學(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對象和DOM對象和字符串之間的轉(zhuǎn)化實(shí)例
下面小編就為大家?guī)硪黄趈Query對象和DOM對象和字符串之間的轉(zhuǎn)化實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
Jquery圖形報(bào)表插件 jqplot簡介及參數(shù)詳解
jqPlot是 一款基于jquery類庫的圖標(biāo)繪制插件。通過jqPlot可以再網(wǎng)頁中繪制線狀、柱狀、餅狀等多種樣式圖表。而且,jqPlot具有插件可擴(kuò)展性 (Pluggability),你可以編寫自己的圖表樣式2012-10-10
jQuery旋轉(zhuǎn)插件jqueryrotate用法詳解
這篇文章主要介紹了jQuery旋轉(zhuǎn)插件jqueryrotate用法,結(jié)合實(shí)例形式詳細(xì)分析了jqueryrotate插件的功能、定義及相關(guān)參數(shù)的使用方法,需要的朋友可以參考下2016-10-10
jQuery實(shí)現(xiàn)的簡單拖動(dòng)層示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的簡單拖動(dòng)層,可實(shí)現(xiàn)響應(yīng)鼠標(biāo)拖動(dòng)div層及動(dòng)態(tài)顯示坐標(biāo)值的功能,涉及jQuery鼠標(biāo)響應(yīng)及頁面元素屬性相關(guān)操作技巧,需要的朋友可以參考下2017-02-02
jquery 查找iframe父級頁面元素的實(shí)現(xiàn)代碼
jquery 查找iframe父級頁面元素的實(shí)現(xiàn)代碼,學(xué)習(xí)jquery的朋友可以參考下。2011-08-08
JQuery實(shí)現(xiàn)地圖坐標(biāo)拾取和地址模糊查詢功能
本文詳細(xì)介紹了使用JQuery、HTML和JavaScript實(shí)現(xiàn)移動(dòng)端地圖位置選取的方法,內(nèi)容包括構(gòu)建地圖頁面、通過點(diǎn)擊獲取經(jīng)緯度、實(shí)現(xiàn)地址模糊查詢與標(biāo)注等功能,文章還提供了完整的代碼示例,并且介紹了百度地圖API的應(yīng)用,幫助開發(fā)者快速掌握地圖位置選點(diǎn)的開發(fā)技術(shù)2024-09-09
jQuery實(shí)現(xiàn)小球點(diǎn)擊發(fā)射動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)小球點(diǎn)擊發(fā)射動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01

