ks-form.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. $.fn.getSelectedIndex = function() {
  2. return $(this).get(0).selectedIndex;
  3. };
  4. $.fn.getSelectedText = function() {
  5. if (this.size() == 0)
  6. return "下拉框中无选项";
  7. else {
  8. var a = this.getSelectedIndex();
  9. return $(this).get(0).options[a].text;
  10. }
  11. };
  12. $.fn.getSelectedValue = function() {
  13. if (this.size() == 0)
  14. return "下拉框中无选中值";
  15. else
  16. return $(this).val();
  17. };
  18. $.fn.setSelectedValue = function(a) {
  19. $(this).get(0).value = a;
  20. };
  21. $.fn.setSelectedText = function(a) {
  22. var b = false;
  23. var c = this.size();
  24. for ( var i = 0; i < c; i++) {
  25. if ($(this).get(0).options[i].text == a) {
  26. $(this).get(0).options[i].selected = true;
  27. b = true;
  28. break;
  29. }
  30. }
  31. if (!b) {
  32. alert("下拉框中不存在该项");
  33. }
  34. };
  35. $.fn.setSelectedIndex = function(a) {
  36. var b = this.size();
  37. if (a >= b || a < 0) {
  38. alert("选中项索引超出范围");
  39. } else {
  40. $(this).get(0).selectedIndex = a;
  41. }
  42. };
  43. $.fn.isExistItem = function(a) {
  44. var b = false;
  45. var c = this.size();
  46. for ( var i = 0; i < c; i++) {
  47. if ($(this).get(0).options[i].value == a) {
  48. b = true;
  49. break;
  50. }
  51. }
  52. return b;
  53. };
  54. $.fn.addOption = function(a, b) {
  55. //if (this.isExistItem(b)) {
  56. // alert("待添加项的值已存在")
  57. //} else {
  58. // $(this).get(0).options.add(new Option(a, b))
  59. //}
  60. $(this).get(0).options.add(new Option(a, b));
  61. };
  62. $.fn.removeItem = function(a) {
  63. if (this.isExistItem(a)) {
  64. var b = this.size();
  65. for ( var i = 0; i < b; i++) {
  66. if ($(this).get(0).options[i].value == a) {
  67. $(this).get(0).remove(i);
  68. break;
  69. }
  70. }
  71. } else {
  72. alert("待删除的项不存在!");
  73. }
  74. };
  75. $.fn.removeIndex = function(a) {
  76. var b = this.size();
  77. if (a >= b || a < 0) {
  78. alert("待删除项索引超出范围");
  79. } else {
  80. $(this).get(0).remove(a);
  81. }
  82. };
  83. $.fn.removeSelected = function() {
  84. var a = this.getSelectedIndex();
  85. this.removeIndex(a);
  86. };
  87. $.fn.clearAll = function() {
  88. $(this).get(0).options.length = 0;
  89. };
  90. $.extend( {
  91. ck_selectAll : function(a) {
  92. $("input[type=checkbox][@name=" + a + "]").each(function() {
  93. if (!this.checked)
  94. this.checked = true;
  95. });
  96. },
  97. ck_cancelAll : function(a) {
  98. $("input[type=checkbox][@name=" + a + "]").each(function() {
  99. if (this.checked)
  100. this.checked = false;
  101. });
  102. },
  103. ck_deSelectAll : function(a) {
  104. $("input[type=checkbox][@name=" + a + "]").each(function() {
  105. if (this.checked)
  106. this.checked = false;
  107. else
  108. this.checked = true;
  109. });
  110. },
  111. ck_getSelectedValue : function(a) {
  112. var b = [];
  113. $("input[type=checkbox][@name=" + a + "][@checked]").each(function() {
  114. if (this.checked) {
  115. b.push(this.value);
  116. }
  117. });
  118. return b;
  119. },
  120. ck_isExistChecked : function(a) {
  121. return $("input[type=checkbox][@name=" + a + "][@checked]").length > 0;
  122. }
  123. });