51JOB的AJAX弹出选择效果

  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>无标题文档</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.  <select name="" onchange="showSelect(this.value)" style="margin-bottom:10px;">
  54.  <option value="0">第0层</option>
  55.  <option value="1">第1层</option>
  56.  <option value="2">第2层</option>
  57.  <option value="3">第3层</option>
  58.  </select>
  59.  <div id="c00">
  60.  <input type="checkbox" name="ck00" onclick="addPreItem()" value="北京"/>北京
  61.  <input type="checkbox" name="ck00" onclick="addPreItem()" value="福建"/>福建
  62.  <input type="checkbox" name="ck00" onclick="addPreItem()" value="四川"/>四川
  63.  <input type="checkbox" name="ck00" onclick="addPreItem()" value="江苏"/>江苏
  64.  </div>
  65.  <div id="c01">
  66.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="上海"/>上海
  67.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="云南"/>云南
  68.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="贵州"/>贵州
  69.  </div>
  70.  <div id="c02">
  71.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="黑龙江"/>黑龙江
  72.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="吉林"/>吉林
  73.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="辽宁"/>辽宁
  74.  </div>
  75.  <div id="c03">
  76.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="美国"/>美国
  77.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="阿富汗"/>阿富汗
  78.  <input type="checkbox" name="ck01" onclick="addPreItem()" value="日本"/>日本
  79.  </div>
  80.  </div>
  81.  </div>
  82.  <div id="preview">
  83.  <div class="tit bgc_eee c_999">
  84.  <h2>您已选择的城市</h2>
  85.  </div>
  86.  <div class="cont" id="previewItem">
  87.  </div>
  88.  </div>
  89.  </div>
  90.  
  91.  <script type="text/javascript">
  92. /* ------使用说明----- */
  93. /*
  94. 添加城市方法:
  95. 添加组:找到id 是 "selectSub"中select标签下,添加option标签 value属性递增,找到 id 是 "selectSub",按照原有格式添加div,其id属性递增
  96. 添加二级傅选矿选项
  97. 复制 id 是 "selectSub" 下任意input标签,粘贴在需要添加的位置。
  98. */
  99. var grow = $("selectSub").getElementsByTagName("option").length; //组数
  100. var showGrow = 0;//已打开组
  101. var selectCount = 0; //已选数量
  102. showSelect(showGrow);
  103. var items = $("selectSub").getElementsByTagName("input");
  104. //alert(maxItem);
  105. //var lenMax = 2;
  106. //alert(1);
  107. function $(o){ //获取对象
  108. if(typeof(o) == "string")
  109. return document.getElementById(o);
  110. return o;
  111. }
  112. function openBg(state){ //遮照打开关闭控制
  113. if(state == 1)
  114. {
  115. $("bg").style.display = "block";
  116. var h = document.body.offsetHeight > document.documentElement.offsetHeight ? document.body.offsetHeight : document.documentElement.offsetHeight;
  117. //alert(document.body.offsetHeight);
  118. //alert(document.documentElement.offsetHeight);
  119. $("bg").style.height = h + "px";
  120. }
  121. else
  122. {
  123. $("bg").style.display = "none";
  124. }
  125. }
  126. function openSelect(state){ //选择城市层关闭打开控制
  127. if(state == 1)
  128. {
  129. $("selectItem").style.display = "block";
  130. $("selectItem").style.left = ($("bg").offsetWidth - $("selectItem").offsetWidth)/2 + "px";
  131. $("selectItem").style.top = document.body.scrollTop + 100 + "px";
  132. }
  133. else
  134. {
  135. $("selectItem").style.display = "none";
  136. }
  137. }
  138. function showSelect(id){
  139. for(var i = 0 ; i < grow ;i++)
  140. {
  141. $("c0" + i).style.display = "none";
  142. }
  143. $("c0" + id).style.display = "block";
  144.  showGrow = id;
  145. }
  146.  function open(id,state){ //显示隐藏控制
  147.  if(state == 1)
  148. $(id).style.display = "block";
  149. $(id).style.diaplay = "none";
  150. }
  151.  function addPreItem(){
  152. $("previewItem").innerHTML = "";
  153.  var len = 0 ;
  154.  for(var i = 0 ; i < items.length ; i++)
  155. {
  156.  if(items[i].checked == true)
  157. {
  158. //len++;
  159. //if(len > lenMax)
  160. //{
  161. // alert("不能超过" + lenMax +"个选项!")
  162. // return false;
  163. //}
  164. var mes = "<input type='checkbox' checked='true' value='"+ items[i].value +"' onclick='copyItem(/"previewItem/",/"previewItem/");same(this);'>" + items[i].value;
  165. $("previewItem").innerHTML += mes;
  166. //alert(items[i].value);
  167. }
  168. }
  169. }
  170. function makeSure(){
  171. //alert(1);
  172. //$("makeSureItem").innerHTML = $("previewItem").innerHTML;
  173. openBg(0);
  174. openSelect(0);
  175. copyItem("previewItem","makeSureItem")
  176. }
  177. function copyHTML(id1,id2){
  178. $(id2).innerHTML = $("id1").innerHTML;
  179. }
  180. function copyItem(id1,id2){
  181.  
  182. var mes = "";
  183. var items2 = $(id1).getElementsByTagName("input");
  184. for(var i = 0 ; i < items2.length ; i++)
  185. {
  186.  if(items2[i].checked == true)
  187. {
  188.  mes += "<input type='checkbox' checked='true' value='"+ items2[i].value +"' οnclick='copyItem(/"" + id2+ "/",/""+ id1 +"/");same(this);'>" + items2[i].value;
  189. }
  190. }
  191. $(id2).innerHTML = "";
  192. $(id2).innerHTML += mes;
  193. //alert($(id2).innerHTML);
  194. }
  195.  function same(ck){
  196.  for(var i = 0 ; i < items.length ; i++)
  197. {
  198.  if(ck.value == items[i].value)
  199. {
  200.  items[i].checked = ck.checked;
  201. }
  202. }
  203. }
  204. /* 鼠标拖动 */
  205.  var oDrag = "";
  206.  var ox,oy,nx,ny,dy,dx;
  207.  function drag(e,o){
  208.  var e = e ? e : event;
  209.  var mouseD = document.all ? 1 : 0;
  210.  if(e.button == mouseD)
  211. {
  212.  oDrag = o.parentNode;
  213. //alert(oDrag.id);
  214.  ox = e.clientX;
  215.  oy = e.clientY;
  216. }
  217. }
  218.  function dragPro(e){
  219.  if(oDrag != "")
  220. {
  221.  var e = e ? e : event;
  222. //$(oDrag).style.left = $(oDrag).offsetLeft + "px";
  223. //$(oDrag).style.top = $(oDrag).offsetTop + "px";
  224.  dx = parseInt($(oDrag).style.left);
  225.  dy = parseInt($(oDrag).style.top);
  226. //dx = $(oDrag).offsetLeft;
  227. //dy = $(oDrag).offsetTop;
  228.  nx = e.clientX;
  229.  ny = e.clientY;
  230. $(oDrag).style.left = (dx + ( nx - ox )) + "px";
  231. $(oDrag).style.top = (dy + ( ny - oy )) + "px";
  232.  ox = nx;
  233.  oy = ny;
  234. }
  235. }
  236.  document.onmouseup = function(){oDrag = "";}
  237.  document.onmousemove = function(event){dragPro(event);}
  238. </script>
  239.  </body>
  240.  </html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值