[jQuery]Plugins clearAll sample
1: (function($) {
2: $.fn.clearAll = function(c) {
3: var $this = $(this);
4: var v = $('input,textarea,select', $this);
5: if (c) v = v.filter('[disabled!="true"][readonly!="readonly"]:not(.textbox_disabled)');
6:
7: v.filter(function() { return this.type.match(/(text|password)/); }).val('');
8: v.filter(':checked').attr('checked', false);
9: v.filter('select').children('option:selected').removeAttr('selected');
10: v.filter('select').children(':first-child').attr('selected', true);
11: }
12:
13: })(jQuery);
用法:
1: // 刪除所有table裡所有文字方塊,下拉選單, checkbox, radiobutton 的資料內容
2: $('table').clearAll();
3:
4: // 刪除所有table裡除唯讀外之文字方塊,下拉選單, checkbox, radiobutton 的資料內容.
5: $('table').clearAll(true);
註: textbox_disabled 是自訂的 css 名稱
如:
<input type="text" class="textbox_disabled" value="123" />