industry_funch.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var ind_flag_arr = new Array(); // 已选中数组
  2. //var ind_flag_arr = new Array('21','31','37');
  3. var Industry = {
  4. // 行业列表
  5. init : function(){
  6. var _str='',_id='';
  7. if (ind_flag_arr.length>0){
  8. for (var i in ind_flag_arr){
  9. _str+=','+ind_a[ind_flag_arr[i]];
  10. _id+=','+ind_flag_arr[i];
  11. }
  12. $('#btn_IndustryID').val(_str.substring(1));
  13. $('#IndustryID').val(_id.substring(1));
  14. }
  15. },
  16. Show : function(){
  17. var output='',flag,output2='';
  18. for (var i in ind_a){
  19. if(isNumber(i)){
  20. flag=in_array(i,ind_flag_arr)?' chkON':'';
  21. output+='<li class="Industry' + i + flag + '" onclick="Industry.Chk(\''+i+'\')">'+ind_a[i]+'</li>';
  22. }
  23. }
  24. for (var i in ind_flag_arr){
  25. if(ind_flag_arr.length > 0){
  26. if(isNumber(i)){
  27. output2+='<li class="Industry' + ind_flag_arr[i] + ' chkON" onclick="Industry.Chk(\''+ind_flag_arr[i]+'\')">'+ind_a[ind_flag_arr[i]]+'</li>';
  28. }
  29. }
  30. }
  31. $('#drag').width('670px');
  32. $('#IndustryList').html('<ul>'+output+'</ul>');
  33. $('#IndustrySelected dd').html(output2);
  34. // 鼠标悬停变色
  35. $('#IndustryAlpha li').hover(function(){$(this).addClass('over')},function(){$(this).removeClass('over')});
  36. },
  37. Chk : function(id){
  38. if(!in_array(id,ind_flag_arr)){
  39. if(ind_flag_arr.length<5){
  40. ind_flag_arr[ind_flag_arr.length]=id;
  41. var html='<li class="Industry'+id+'" onclick="Industry.Chk(\''+id+'\')">'+ind_a[id]+'</li>';
  42. $('#IndustrySelected dd').append(html);
  43. $('.Industry'+id).addClass('chkON');
  44. $('#IndustrySelected li').hover(function(){$(this).addClass('over')},function(){$(this).removeClass('over')});
  45. }else{
  46. alert('您最多能选择5项');
  47. return false;
  48. }
  49. }else{
  50. for (var i in ind_flag_arr){
  51. if(isNumber(i)){
  52. if(ind_flag_arr[i]==id) ind_flag_arr.splice(i,1);
  53. }
  54. }
  55. $('#IndustrySelected .Industry'+id).remove();
  56. $('.Industry'+id).removeClass('chkON');
  57. }
  58. },
  59. // 确定
  60. confirm : function(org){
  61. var indStr='';
  62. for(var i in ind_flag_arr){
  63. if(isNumber(i)) {
  64. indStr += ind_a[ind_flag_arr[i]];
  65. }
  66. }
  67. $('#'+org.id).val(indStr);
  68. $('#'+org.id).focus();
  69. //$('#IndustryID').val(ind_flag_arr);
  70. boxAlpha();
  71. },
  72. /* ****************************** 单选 ********************************* */
  73. // 单选输出
  74. Show2 : function(){
  75. var output='',flag,output2='';
  76. for (var i in ind_a){
  77. output+='<li onclick="Industry.Chk2(\''+i+'\')">'+ind_a[i]+'</li>';
  78. }
  79. $('#drag').width('670px');
  80. $('#IndustryList').html('<ul>'+output+'</ul>');
  81. // 鼠标悬停变色
  82. $('#IndustryAlpha li').hover(function(){$(this).addClass('over')},function(){$(this).removeClass('over')});
  83. },
  84. Chk2 : function(id){
  85. $('#btn_IndustryID_2').val(ind_a[id]);
  86. $('#IndustryID_2').val(id);
  87. boxAlpha();
  88. }
  89. }
  90. // 多选
  91. function IndustrySelect(org){
  92. var dragHtml ='<div id="IndustryAlpha">'; //行业
  93. dragHtml+=' <dl id="IndustrySelected"><dt>已选行业:</dt><dd></dd></dl>';
  94. dragHtml+=' <div id="IndustryList"></div>';//行业列表
  95. dragHtml+='</div>';
  96. $('#drag_h').html('<b>请选择行业(您最多能选择5项)</b><span onclick="Industry.confirm('+org+')">确定</span>');
  97. $('#drag_con').html(dragHtml);
  98. Industry.Show();
  99. boxAlpha();
  100. draglayer();
  101. }
  102. // 单选
  103. function IndustrySelect_2(){
  104. var dragHtml ='<div id="IndustryAlpha">'; //行业
  105. dragHtml+=' <div id="IndustryList" class="radio"></div>';//行业列表
  106. dragHtml+='</div>';
  107. $('#drag_h').html('<b>请选择行业</b><span onclick="boxAlpha()">关闭</span>');
  108. $('#drag_con').html(dragHtml);
  109. Industry.Show2();
  110. boxAlpha();
  111. draglayer();
  112. }
  113. function isNumber(str)
  114. {
  115. var reg = /^\d+$/;
  116. if (reg.test(str))
  117. return true;
  118. else
  119. return false;
  120. }
  121. /**
  122. * 搜索某个值是否存在数组之内
  123. * @param needle 搜索的值
  124. * @param haystack 被搜索的数组
  125. * */
  126. function in_array(needle, haystack) {
  127. if (haystack.constructor != Array) {
  128. haystack = String(haystack).split(',');
  129. }
  130. var length = haystack.length;
  131. for(var i = 0; i < length; i++) {
  132. if(haystack[i] == needle) return true;
  133. }
  134. return false;
  135. }