仿51job.com城市选择框特效

来源:互联网 发布:centos nfs server 编辑:程序博客网 时间:2024/04/30 02:57

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5. <title>仿51job.com城市选择框特效</title> 
  6. <style type="text/css"> 
  7. <!-- 
  8. body{padding-top:50px;font-size:12px;} 
  9. h2{margin:0px;padding:0px;font-size:12px;font-weight:bold;} 
  10. .bton{border:1px solid #CCC;background:#DDD;} 
  11. .cont{padding:10px;} 
  12. #main{width:400px;margin:0px auto;} 
  13. #selectItem{background:#FFF;position:absolute;top:0px;left:center;border:1px solid #000;overflow:hidden;margin-top:10px;width:400px;z-index:2;} 
  14. #preview{margin:1px;border:1px solid #CCC;} 
  15. #result{border:1px solid #CCC;margin-top:10px;} 
  16. .tit{line-height:20px;height:20px;margin:1px;padding-left:10px;} 
  17. .bgc_ccc{background:#CCC;} 
  18. .bgc_eee{background:#eee;} 
  19. .c_999{color:#999} 
  20. .pointer{cursor:pointer;} 
  21. .left{float:left;} 
  22. .right{float:right;} 
  23. .cls{clear:both;font-size:0px;height:0px;overflow:hidden;} 
  24. #bg{background:#CCC;filter:alpha(opacity=70);opacity:0.7;width:100%;;position:absolute;left:0px;top:0px;display:none;z-index:1;} 
  25. .hidden{display:none;} 
  26. .move{cursor:move;} 
  27. --> 
  28. </style> 
  29. </head> 
  30. <body> 
  31. <div id="main"> 
  32.   <input name="button" type="button" class="bton pointer" value="请选择" onclick="openBg(1);openSelect(1)"/> 
  33.   <div id="result"> 
  34.   <div class="tit bgc_eee"> 
  35.    <h2>您已选择的城市汇总</h2> 
  36.   </div>  
  37.   <div class="cont" id="makeSureItem"> 
  38.   </div> 
  39.   </div> 
  40. </div> 
  41.   
  42. <div id="bg"> 
  43. </div> 
  44. <div id="selectItem" class="hidden"> 
  45.   <div class="tit bgc_ccc move" onmousedown="drag(event,this)"> 
  46.    <h2 class="left">请选择城市</h2> 
  47.    <span class="pointer right" onclick="openBg(0);openSelect(0);">[取消]</span> 
  48.    <span class="pointer right" onclick="makeSure();">[确定]</span>    
  49.   </div> 
  50.   <div class="cls"></div> 
  51.   <div class="cont"> 
  52.    <div id="selectSub"> 
  53.      <div id="c00"> 
  54.      <input type="checkbox" name="ck00" onclick="addPreItem()" value="北京"/>北京 
  55.      <input type="checkbox" name="ck00" onclick="addPreItem()" value="福建"/>福建 
  56.      <input type="checkbox" name="ck00" onclick="addPreItem()" value="四川"/>四川  
  57.      <input type="checkbox" name="ck00" onclick="addPreItem()" value="江苏"/>江苏 
  58.     </div> 
  59.     <div id="c01"> 
  60.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="上海"/>上海 
  61.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="云南"/>云南 
  62.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="贵州"/>贵州 
  63.     </div> 
  64.     <div id="c02"> 
  65.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="黑龙江"/>黑龙江 
  66.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="吉林"/>吉林 
  67.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="辽宁"/>辽宁 
  68.     </div> 
  69.     <div id="c03"> 
  70.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="美国"/>美国 
  71.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="阿富汗"/>阿富汗 
  72.      <input type="checkbox" name="ck01" onclick="addPreItem()" value="日本"/>日本 
  73.     </div> 
  74.    </div> 
  75.   </div> 
  76.   <div id="preview"> 
  77.    <div class="tit bgc_eee c_999"> 
  78.     <h2>您已选择的城市</h2> 
  79.    </div>  
  80.    <div class="cont" id="previewItem"> 
  81.    </div> 
  82.   </div> 
  83. </div> 
  84.   
  85. <script type="text/javascript"> 
  86. /* ------使用说明----- */ 
  87. /* 
  88.  添加城市方法: 
  89.      添加组:找到id 是 "selectSub"中select标签下,添加option标签 value属性递增,找到 id 是 "selectSub",按照原有格式添加div,其id属性递增 
  90.  添加二级傅选矿选项 
  91.   复制 id 是 "selectSub" 下任意input标签,粘贴在需要添加的位置。 
  92. */ 
  93. var grow = $("selectSub").getElementsByTagName("option").length; //组数 
  94. var showGrow = 0;//已打开组 
  95. var selectCount = 0; //已选数量  
  96. showSelect(showGrow); 
  97. var items = $("selectSub").getElementsByTagName("input"); 
  98. //alert(maxItem); 
  99. //var lenMax = 2;  
  100. //alert(1); 
  101. function $(o){ //获取对象 
  102.  if(typeof(o) == "string") 
  103.  return document.getElementById(o); 
  104.  return o; 
  105. function openBg(state){ //遮照打开关闭控制 
  106.  if(state == 1) 
  107.  { 
  108.   $("bg").style.display = "block"
  109.   var h = document.body.offsetHeight > document.documentElement.offsetHeight ? document.body.offsetHeight : document.documentElement.offsetHeight; 
  110.  //alert(document.body.offsetHeight); 
  111.  //alert(document.documentElement.offsetHeight); 
  112.   $("bg").style.height = h + "px"; 
  113.  } 
  114.  else 
  115.  { 
  116.   $("bg").style.display = "none"
  117.  }  
  118. function openSelect(state){ //选择城市层关闭打开控制 
  119.  if(state == 1)  
  120.  { 
  121.   $("selectItem").style.display = "block"
  122.   $("selectItem").style.left = ($("bg").offsetWidth - $("selectItem").offsetWidth)/2 + "px"; 
  123.   $("selectItem").style.top = document.body.scrollTop + 100 + "px";   
  124.  } 
  125.  else 
  126.  { 
  127.   $("selectItem").style.display = "none"
  128.  } 
  129. function showSelect(id){ 
  130.  for(var i = 0 ; i < grow ;i++) 
  131.  { 
  132.   $("c0" + i).style.display = "none"
  133.  } 
  134.  $("c0" + id).style.display = "block"
  135.  showGrow = id
  136. function open(id,state){ //显示隐藏控制 
  137.  if(state == 1) 
  138.  $(id).style.display = "block"
  139.  $(id).style.diaplay = "none"
  140. function addPreItem(){  
  141.  $("previewItem").innerHTML = ""
  142.  var len = 0 ; 
  143.  for(var i = 0 ; i < items.length ; i++) 
  144.  { 
  145.   if(items[i].checked == true) 
  146.   { 
  147.    //len++; 
  148.    //if(len > lenMax) 
  149.    //{ 
  150.    // alert("不能超过" + lenMax +"个选项!") 
  151.    // return false; 
  152.    //} 
  153.    var mes = "<input type='checkbox' checked='true' value='"+ items[i].value +"' onclick='copyItem(\"previewItem\",\"previewItem\");same(this);'>" + items[i].value; 
  154.    $("previewItem").innerHTML += mes; 
  155.    //alert(items[i].value); 
  156.   } 
  157.  } 
  158. function makeSure(){ 
  159.  //alert(1); 
  160.  //$("makeSureItem").innerHTML = $("previewItem").innerHTML; 
  161.  openBg(0); 
  162.  openSelect(0); 
  163.  copyItem("previewItem","makeSureItem")  
  164. function copyHTML(id1,id2){ 
  165.  $(id2).innerHTML = $("id1").innerHTML; 
  166. function copyItem(id1,id2){ 
  167.   
  168.  var mes = ""
  169.  var items2 = $(id1).getElementsByTagName("input"); 
  170.  for(var i = 0 ; i < items2.length ; i++) 
  171.  { 
  172.   if(items2[i].checked == true) 
  173.   { 
  174.    mes += "<input type='checkbox' checked='true' value='"+ items2[i].value +"' onclick='copyItem(\"" + id2+ "\",\""+ id1 +"\");same(this);'>" + items2[i].value;    
  175.   } 
  176.  } 
  177.  $(id2).innerHTML = ""
  178.  $(id2).innerHTML += mes; 
  179.  //alert($(id2).innerHTML); 
  180. function same(ck){ 
  181.  for(var i = 0 ; i < items.length ; i++) 
  182.  { 
  183.   if(ck.value == items[i].value) 
  184.   { 
  185.    items[i].checked = ck.checked; 
  186.   } 
  187.  } 
  188. }  
  189. /* 鼠标拖动 */ 
  190. var oDrag = ""
  191. var ox,oy,nx,ny,dy,dx; 
  192. function drag(e,o){ 
  193.  var ee = e ? e : event; 
  194.  var mouseD = document.all ? 1 : 0; 
  195.  if(e.button == mouseD) 
  196.  { 
  197.   ooDrag = o.parentNode; 
  198.   //alert(oDrag.id); 
  199.   ox = e.clientX; 
  200.   oy = e.clientY;   
  201.  } 
  202. function dragPro(e){ 
  203.  if(oDrag != "") 
  204.  {  
  205.   var ee = e ? e : event; 
  206.   //$(oDrag).style.left = $(oDrag).offsetLeft + "px"; 
  207.   //$(oDrag).style.top = $(oDrag).offsetTop + "px"; 
  208.   dx = parseInt($(oDrag).style.left); 
  209.   dy = parseInt($(oDrag).style.top); 
  210.   //dx = $(oDrag).offsetLeft; 
  211.   //dy = $(oDrag).offsetTop; 
  212.   nx = e.clientX; 
  213.   ny = e.clientY; 
  214.   $(oDrag).style.left = (dx + ( nx - ox )) + "px"; 
  215.   $(oDrag).style.top = (dy + ( ny - oy )) + "px"; 
  216.   ox = nx
  217.   oy = ny
  218.  } 
  219. document.onmouseup = function(){oDrag = "";} 
  220. document.onmousemove = function(event){dragPro(event);} 
  221. </script> 
  222. </body> 
  223. </html> 

 

0 0
原创粉丝点击