123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- $.fn.getSelectedIndex = function() {
- return $(this).get(0).selectedIndex;
- };
- $.fn.getSelectedText = function() {
- if (this.size() == 0)
- return "下拉框中无选项";
- else {
- var a = this.getSelectedIndex();
- return $(this).get(0).options[a].text;
- }
- };
- $.fn.getSelectedValue = function() {
- if (this.size() == 0)
- return "下拉框中无选中值";
- else
- return $(this).val();
- };
- $.fn.setSelectedValue = function(a) {
- $(this).get(0).value = a;
- };
- $.fn.setSelectedText = function(a) {
- var b = false;
- var c = this.size();
- for ( var i = 0; i < c; i++) {
- if ($(this).get(0).options[i].text == a) {
- $(this).get(0).options[i].selected = true;
- b = true;
- break;
- }
- }
- if (!b) {
- alert("下拉框中不存在该项");
- }
- };
- $.fn.setSelectedIndex = function(a) {
- var b = this.size();
- if (a >= b || a < 0) {
- alert("选中项索引超出范围");
- } else {
- $(this).get(0).selectedIndex = a;
- }
- };
- $.fn.isExistItem = function(a) {
- var b = false;
- var c = this.size();
- for ( var i = 0; i < c; i++) {
- if ($(this).get(0).options[i].value == a) {
- b = true;
- break;
- }
- }
- return b;
- };
- $.fn.addOption = function(a, b) {
- //if (this.isExistItem(b)) {
- // alert("待添加项的值已存在")
- //} else {
- // $(this).get(0).options.add(new Option(a, b))
- //}
- $(this).get(0).options.add(new Option(a, b));
- };
- $.fn.removeItem = function(a) {
- if (this.isExistItem(a)) {
- var b = this.size();
- for ( var i = 0; i < b; i++) {
- if ($(this).get(0).options[i].value == a) {
- $(this).get(0).remove(i);
- break;
- }
- }
- } else {
- alert("待删除的项不存在!");
- }
- };
- $.fn.removeIndex = function(a) {
- var b = this.size();
- if (a >= b || a < 0) {
- alert("待删除项索引超出范围");
- } else {
- $(this).get(0).remove(a);
- }
- };
- $.fn.removeSelected = function() {
- var a = this.getSelectedIndex();
- this.removeIndex(a);
- };
- $.fn.clearAll = function() {
- $(this).get(0).options.length = 0;
- };
- $.extend( {
- ck_selectAll : function(a) {
- $("input[type=checkbox][@name=" + a + "]").each(function() {
- if (!this.checked)
- this.checked = true;
- });
- },
- ck_cancelAll : function(a) {
- $("input[type=checkbox][@name=" + a + "]").each(function() {
- if (this.checked)
- this.checked = false;
- });
- },
- ck_deSelectAll : function(a) {
- $("input[type=checkbox][@name=" + a + "]").each(function() {
- if (this.checked)
- this.checked = false;
- else
- this.checked = true;
- });
- },
- ck_getSelectedValue : function(a) {
- var b = [];
- $("input[type=checkbox][@name=" + a + "][@checked]").each(function() {
- if (this.checked) {
- b.push(this.value);
- }
- });
- return b;
- },
- ck_isExistChecked : function(a) {
- return $("input[type=checkbox][@name=" + a + "][@checked]").length > 0;
- }
- });
|