MultiSelectsBox.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //$(function () {
  2. // $("#FirstBox option:first,#SecondBox option:first").attr("selected", true);
  3. // $("#FirstBox").dblclick(function () {
  4. // $("option:selected", this).clone().appendTo("#SecondBox");
  5. // $("option:selected", this).remove();
  6. // });
  7. // $("#SecondBox").dblclick(function () {
  8. // $("option:selected", this).clone().appendTo("#FirstBox");
  9. // $("option:selected", this).remove();
  10. // });
  11. // $("#add").click(function () {
  12. // $("#FirstBox option:selected").clone().appendTo("#SecondBox");
  13. // $("#FirstBox option:selected").remove();
  14. // });
  15. // $("#remove").click(function () {
  16. // $("#SecondBox option:selected").clone().appendTo("#FirstBox");
  17. // $("#SecondBox option:selected").remove();
  18. // });
  19. // $("#addall").click(function () {
  20. // $("#FirstBox option").clone().appendTo("#SecondBox");
  21. // $("#FirstBox option").remove();
  22. // });
  23. // $("#removeall").click(function () {
  24. // $("#SecondBox option").clone().appendTo("#FirstBox");
  25. // $("#SecondBox option").remove();
  26. // });
  27. // $("#FirstBoxup").click(function () {
  28. // var so = $("#FirstBox option:selected");
  29. // if (so.get(0).index != 0) {
  30. // so.each(function () {
  31. // $(this).prev().before($(this));
  32. // });
  33. // }
  34. // });
  35. // $("#FirstBoxdown").click(function () {
  36. // var alloptions = $("#FirstBox option");
  37. // var so = $("#FirstBox option:selected");
  38. // if (so.get(so.length - 1).index != alloptions.length - 1) {
  39. // for (i = so.length - 1; i >= 0; i--) {
  40. // var item = $(so.get(i));
  41. // item.insertAfter(item.next());
  42. // }
  43. // }
  44. // });
  45. // $("#SecondBoxup").click(function () {
  46. // var so = $("#SecondBox option:selected");
  47. // if (so.get(0).index != 0) {
  48. // so.each(function () {
  49. // $(this).prev().before($(this));
  50. // });
  51. // }
  52. // });
  53. // $("#SecondBoxdown").click(function () {
  54. // var alloptions = $("#SecondBox option");
  55. // var so = $("#SecondBox option:selected");
  56. // if (so.get(so.length - 1).index != alloptions.length - 1) {
  57. // for (i = so.length - 1; i >= 0; i--) {
  58. // var item = $(so.get(i));
  59. // item.insertAfter(item.next());
  60. // }
  61. // }
  62. // });
  63. //});
  64. (function ($) {
  65. $.fn.MultiSelectsBox = function (options, param) {
  66. function ConcatColumnTag(str) {
  67. var html = "<td>" + str + "</td>";
  68. return html;
  69. };
  70. function ConcatRowTag(str) {
  71. var html = "<tr>" + str + "</tr>";
  72. return html;
  73. };
  74. var containerID = $(this).attr("id");
  75. var identityObject = {
  76. /// <summary>
  77. /// MultiSelectsBox内标签对象的id列表
  78. /// </summary>
  79. firstBoxItemUpBtn: containerID + "_firstBoxItemUpBtn",
  80. fristBoxItemDownBtn: containerID + "_fristBoxItemDownBtn",
  81. secondBoxItemUpBtn: containerID + "_secondBoxItemUpBtn",
  82. secondBoxItemDownBtn: containerID + "_secondBoxItemDownBtn",
  83. firstBox: containerID + "_firstBox",
  84. secondBox: containerID + "_secondBox",
  85. allItemRightMoveBtn: containerID + "_allItemRightMoveBtn",
  86. allItemLeftMoveBtn: containerID + "_allItemLeftMoveBtn",
  87. itemRightMoveBtn: containerID + "_itemRightMoveBtn",
  88. itemLeftMoveBtn: containerID + "_itemLeftMoveBtn"
  89. };
  90. var firstBoxItemUpBtnHtml = "<input type=\"button\" name=\"firstBoxItemUpBtn\" id=\"" + identityObject.firstBoxItemUpBtn + "\" value=\"上&nbsp;&nbsp;移\" title=\"上移\" style=\"width:70px;\" /><br />";
  91. var fristBoxItemDownBtnHtml = "<input type=\"button\" name=\"fristBoxItemDownBtn\" id=\"" + identityObject.fristBoxItemDownBtn + "\" value=\"下&nbsp;&nbsp;移\" title=\"下移\" style=\"width:70px;\" />";
  92. var secondBoxItemUpBtnHtml = "<input type=\"button\" name=\"secondBoxItemUpBtn\" id=\"" + identityObject.secondBoxItemUpBtn + "\" value=\"上&nbsp;&nbsp;移\" title=\"上移\" style=\"width:70px;\" /><br />";
  93. var secondBoxItemDownBtnHtml = "<input type=\"button\" name=\"secondBoxItemDownBtn\" id=\"" + identityObject.secondBoxItemDownBtn + "\" value=\"下&nbsp;&nbsp;移\" title=\"下移\" style=\"width:70px;\" />";
  94. var firstBoxHtml = "<select name=\"firstBox\" size=\"10\" multiple=\"multiple\" id=\"" + identityObject.firstBox + "\" style=\"width: 150px;\" mce_style=\" width:150px;\"></select>";
  95. var secondBoxHtml = "<select name=\"secondBox\" size=\"10\" multiple=\"multiple\" id=\"" + identityObject.secondBox + "\" style=\"width: 150px;\" mce_style=\" width:150px;\"></select>";
  96. var allItemRightMoveBtnHtml = "<input type=\"button\" name=\"allItemRightMoveBtn\" id=\"" + identityObject.allItemRightMoveBtn + "\" value=\"全部右移\" title=\"全部右移\" style=\"width:70px;\" />";
  97. var allItemLeftMoveBtnHtml = "<input type=\"button\" name=\"allItemLeftMoveBtn\" id=\"" + identityObject.allItemLeftMoveBtn + "\" value=\"全部左移\" title=\"全部左移\" style=\"width:70px;\" />";
  98. var itemRightMoveBtnHtml = "<input type=\"button\" name=\"itemRightMoveBtn\" id=\"" + identityObject.itemRightMoveBtn + "\" value=\"右&nbsp;&nbsp;移\" title=\"右移动\" style=\"width:70px;\" />";
  99. var itemLeftMoveBtnHtml = "<input type=\"button\" name=\"itemLeftMoveBtn\" id=\"" + identityObject.itemLeftMoveBtn + "\" value=\"左&nbsp;&nbsp;移\" title=\"左移\" style=\"width:70px;\" />";
  100. var columnOneHtml = ConcatColumnTag(firstBoxItemUpBtnHtml.concat("<br />").concat(fristBoxItemDownBtnHtml));
  101. var columnTwoHtml = ConcatColumnTag(firstBoxHtml);
  102. var columnThreeHtml = ConcatColumnTag(allItemRightMoveBtnHtml.concat("<br />").concat(itemRightMoveBtnHtml).concat("<br />").concat(itemLeftMoveBtnHtml).concat("<br />").concat(allItemLeftMoveBtnHtml));
  103. var columnFourHtml = ConcatColumnTag(secondBoxHtml);
  104. var columnFiveHtml = ConcatColumnTag(secondBoxItemUpBtnHtml.concat("<br />").concat(secondBoxItemDownBtnHtml));
  105. var rowsHtml = ConcatRowTag((columnOneHtml.concat(columnTwoHtml).concat(columnThreeHtml).concat(columnFourHtml).concat(columnFiveHtml)));
  106. var container = $("#" + containerID);
  107. container.append(rowsHtml);
  108. };
  109. $.fn.MultiSelectsBox.defaults = {
  110. };
  111. })(jQuery);