网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计资源 > .Net编程 > 正文

.net实现51job地区选择效果

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

最终效果图:

难点: 定位,其实不难, 取得父元素(省)的位置,然后设置 市(初始隐藏)的位置 = 父元素位置偏移n个px
id为pop 的div是模式窗口
说一下流程吧
1.ajax读出所有省市
2.市放在一个div里面,初始是隐藏的,然后给每一个省加一个onclick事件,控制这个省的市显示还是隐藏
3.完成。
说得简单了点,不过看代码就看明白了!有不明白可以在这里留言,我会关注!
html代码

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="test_Default" %> 
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <html xmlns="http://www.w3.org/1999/xhtml" > 
  4. <head runat="server"> 
  5.     <title>无标题页</title> 
  6.     <script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script> 
  7.      
  8.     <script> 
  9.     var xmlHttp; 
  10. function createXMLHttpRequest() 
  11.     if(window.ActiveXObject) 
  12.     { 
  13.         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
  14.     } 
  15.     else if(window.XMLHttpRequest) 
  16.     { 
  17.         xmlHttp = new XMLHttpRequest(); 
  18.     } 
  19. function startRequest() 
  20.     createXMLHttpRequest(); 
  21.     try 
  22.     {        
  23.         xmlHttp.onreadystatechange = handleStateChange
  24.         xmlHttp.open("GET", "Default.aspx?ct=1", true); 
  25.         xmlHttp.send(null); 
  26.     } 
  27.     catch(exception ) 
  28.     { 
  29.     alert(exception); 
  30.         alert("请稍候再试!"); 
  31.     } 
  32. function handleStateChange() 
  33. {     
  34.     if(xmlHttp.readyState == 4) 
  35.     {         
  36.         if (xmlHttp.status == 200 || xmlHttp.status == 0) 
  37.         {    
  38.             var param = xmlHttp.responseText;    
  39.             $("#divlist").append(param); 
  40.             alert(param); 
  41.         } 
  42.     } 
  43.  function cc(){ 
  44.     $('#divdialog').fadeIn('fast'); 
  45.     $('#pop').css({'width': '100%','height': '100%','display': 'inline'}); 
  46.     startRequest(); 
  47.     } 
  48.      
  49.     function selectitem(obj){ 
  50.     $("#txt1").val(obj); 
  51.     } 
  52.    
  53.     function showc(obj,objname){ 
  54.     if($("#divct"+obj).text() == ""){ 
  55.     selectitem(objname); //如果没有市,就选择省 
  56.     }else{ 
  57.       var pos = $("#apro"+obj).position();   //父元素位置    
  58.       var left = pos.left+40+ "px"; //偏移量 
  59.       var top = pos.top+15+ "px"; 
  60.       $("#divct"+obj).css({ 
  61.         "top": top, 
  62.         "left":left, 
  63.         "background":"#F3FBEA", 
  64.         "color":"#666600" 
  65.     }).show(); 
  66.      
  67.     setTimeout(hidect2(obj),4000);//4秒定时关闭 
  68.     }    
  69.     } 
  70.      
  71.     function hidect(obj){ 
  72.     $("#divct"+obj).hide(); 
  73.     } 
  74.     function hidect2(obj){ 
  75.     return function(){hidect(obj);} 
  76.     } 
  77.     function closect(){ 
  78.     $("#divdialog").hide(); 
  79.     $('#pop').css({'width': '0','height': '0','display': 'none'}); 
  80.     } 
  81.     
  82.     
  83.      
  84.     </script> 
  85.      
  86. <style> 
  87. .proul{list-style:none} 
  88. .proul li{width:100px;height:30px;float:left; cursor:pointer} 
  89. .ctul{list-style:none} 
  90. .ctul li{width:100px;height:30px;float:left; cursor:pointer} 
  91. .ctdiv{display:none;position: absolute; border:1px #666600 solid; width:auto; height:auto} 
  92. .dtl{font-size:12px; color:White; font-weight:bold; cursor:pointer} 
  93. .f_r{float:right} 
  94. .f_l{float:left} 
  95. </style> 
  96. </head> 
  97. <body> 
  98.     <form id="form1" runat="server"> 
  99.      
  100.         <input id="Button1" type="button" value="选择地区" onclick="cc();" /> 
  101.     <div id="pop" style="background-color:#000000;position: absolute ;top:0;left:0;z-index:1;display:none;filter:Alpha(opacity=30);"></div> 
  102.      
  103.     <div id="divdialog" style="border: #4b8500 1px solid;display: none; left: 217px; background-image: url(../images/t_bg.jpg); width: 477px;  background-repeat: repeat-x; 
  104.         position: absolute; top: 172px; height: 350px; background-color: #faffeb; z-index:99999"> 
  105.         <div style="padding-right: 5px; overflow: hidden; line-height: 25px; height: 25px;text-align: right"> 
  106.             <span  style="float: left; padding:4px 0px 4px 0px" ><img src="../images/t_bg_l.gif" width="16" height="16" /></span> 
  107.             <span class="dtl f_l">请选择地区</span>             
  108.             <span onclick="closect();" class="dtl f_r">[关闭]</span> 
  109.                <span onclick="closect();$('#txt1').val('不限');" class="dtl f_r">[不限]</span> 
  110.         </div> 
  111.         <div id="divlist" style="font-size: 12px; margin: 0px auto; width: 462px; color: #000; height:320px; overflow:scroll; text-align:left" runat="server"> 
  112.              
  113.             </div> 
  114.              
  115.     </div> 
  116.         <input id="txt1" type="text" /> 
  117.     </form> 
  118. </body> 
  119. </html> 

后台输出代码:

  1. private void Bind() 
  2.     { 
  3.         IList<heyjob.Model.c_Province> listP = bllP.DataTableToList(bllP.GetAllList().Tables[0]); 
  4.         string arr = string.Empty; 
  5.         string ct = string.Empty; 
  6.         for (int i = 0; i < listP.Count; i++) 
  7.         { 
  8.             IList<heyjob.Model.c_City> listC = bllC.DataTableToList(bllC.GetList("provinceid='" + listP[i].ProvinceID + "'").Tables[0]); 
  9.  
  10.             arr += "<ul class='proul'><div id='divpro" + listP[i].ProvinceID + "'>"
  11.             arr += "<li><a id='apro" + listP[i].ProvinceID + "' onclick=showc('" + listP[i].ProvinceID + "'" +",'" + listP[i].ProvinceName + "');>" + listP[i].ProvinceName + "</a></li>"
  12.             arr += "</div></ul>"
  13.  
  14.             ct += "<div class='ctdiv' id='divct" + listP[i].ProvinceID + "'><ul class='ctul'>"
  15.             for (int j = 0; j < listC.Count; j++) 
  16.             { 
  17.                 if (listC.Count > 0) 
  18.                 { 
  19.                     if (listC[j].ProvinceID == listP[i].ProvinceID) 
  20.                     { 
  21.                         if (j == 0) 
  22.                         { 
  23.                             ct += listP[i].ProvinceName + "<br/><br/>"
  24.                         } 
  25.                         ct += "<li><a onclick=selectitem('" + listC[j].CityName + "');>" + listC[j].CityName + "</a></li>"
  26.                     } 
  27.                 } 
  28.             } 
  29.             ct += "</ul></div>"
  30.             arr += ct; 
  31.  
  32.         } 
  33.  
  34.         Response.Write(arr); 
  35.         Response.End(); 
  36.     } 
设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师