這篇文章主要介紹了基于jQuery實(shí)現(xiàn)仿51job城市選擇功能實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
前些文章用寫(xiě)過(guò),省市縣三級(jí)聯(lián)動(dòng),但是感覺(jué)選擇的時(shí)候不夠直觀,現(xiàn)在改進(jìn)了下,效果如下圖
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="City.aspx.cs" Inherits="System_Select_City" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="../js/jquery-1.7.min.js" ></script>
<style type="text/css">
#provinceDiv{ list-style:none;}
#provinceDiv li{ list-style:none; border-bottom:1px dotted #ccc; width:400px; height:20px;margin-bottom:3px;}
#provinceDiv li span{ display:block; width:60px; height:20px; float:left; line-height:20px; text-align:center; position:relative;}
#provinceDiv li span:hover{ background:#fb0;}
#provinceDiv li span.current{ background:#fb0;}
div.cityDiv{ border:1px solid #ccc; width:auto; width:100px;_width:100px; height:100px;_height:100px;height:auto; background:#eff7ff; display:none; position:absolute; padding:2px;}
div.cityDiv a{ display:block; text-decoration:none; color:#000;}
div.cityDiv a:hover{ background:#fb0;}
</style>
<script type="text/javascript">
$(function () {
var isoncityDiv = false; //是否在cityDiv上,默認(rèn)為false
$("span").bind("click", function () {
var spanid = $(this).attr("id"); //獲取當(dāng)前spanid
$("span").not("#" + spanid).removeClass("current");
$(this).addClass("current");
$("div.cityDiv").remove(); //立即移除所有動(dòng)態(tài)創(chuàng)建的div
var spanCurrent = $("#" + $(this).attr("id")); //當(dāng)前點(diǎn)擊的sapn對(duì)象
var tipDiv = $("<div id='city_" + $(this).attr("id") + "' class='cityDiv'></div>"); //動(dòng)態(tài)創(chuàng)建城市div
tipDiv.html(System_Select_City.GetCity(spanid).value);//后臺(tái)輸出的數(shù)據(jù)包含城市數(shù)據(jù)
tipDiv.bind("mouseover", function () {
tipDiv.show();
isoncityDiv = true; //鼠標(biāo)在其上為true
}).bind("mouseout", function () {
tipDiv.hide();
});
$("body").append(tipDiv); //加入body
var top = spanCurrent.offset().top; //獲取top
var left = spanCurrent.offset().left; //獲取left
tipDiv.offset({ top: top + 20, left: left + 60 });
tipDiv.show(); //獲取顯示div
}).bind("mouseout", function () {
var spanCurrent = $("#city_" + $(this).attr("id"));
var a = function () {
if (!isoncityDiv) { //不在 彈出的div上時(shí)候 執(zhí)行
spanCurrent.remove();
}
clearTimeout(int);
};
var int = setTimeout(a, 3000);
});
});
//關(guān)閉談出口
function show(title) {
parent.closeDiv(title);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul id="provinceDiv">
<li> <a>直轄市</a></li>
<li>
<span id="11">北京</span>
<span id="31">上海</span>
<span id="50">重慶</span>
<span id="12">天津</span>
</li>
<li><a>省區(qū)</a></li>
<li>
<span id="13">河北</span>
<span id="14">山西</span>
<span id="15">內(nèi)蒙古</span>
<span id="21">遼寧</span>
<span id="22">吉林</span>
<span id="23">黑龍江</span>
</li>
<li>
<span id="32">江蘇</span>
<span id="33">浙江</span>
<span id="34">安徽</span>
<span id="35">福建</span>
<span id="36">江西</span>
<span id="37">山東</span>
</li>
<li>
<span id="41">河南</span>
<span id="42">湖北</span>
<span id="43">湖南</span>
<span id="44">廣東</span>
<span id="45">廣西</span>
<span id="46">海南</span>
</li>
<li>
<span id="51">四川</span>
<span id="52">貴州</span>
<span id="53">云南</span>
<span id="54">西藏</span>
<span id="61">陜西</span>
<span id="62">甘肅</span>
</li>
<li>
<span id="63">青海</span>
<span id="64">寧夏</span>
<span id="65">新疆</span>
<span id="71">臺(tái)灣</span>
<span id="81">香港</span>
<span id="91">澳門(mén)</span>
</li>
</ul>
</div>
</form>
</body>
</html>
以上內(nèi)容給大家介紹了基于jQuery實(shí)現(xiàn)仿51job城市選擇功能實(shí)例代碼,希望對(duì)大家有所幫助!