首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

一个JS选择地市的有关问题!请高手解决

2012-02-09 
一个JS选择地市的问题!请高手解决?大侠们:我做了一个选择地市的功能!可是每次我将鼠标移动到地市的时候,就

一个JS选择地市的问题!请高手解决?
大侠们:
  我做了一个选择地市的功能!可是每次我将鼠标移动到地市的时候,就自动隐藏了地市选择的DIV,我搞不明白什么回事,大家看看我的代码哪里有问题。

------------------------------以下是HTML代码-----------------------------------------------
<div class="changeCity" id="changeCity" onmouseout="hideChooseCity(this)"><!-- class="micon" 去掉样式 -->
  <!-- [--><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="background-position: -254px -131px;"></span></span><!-- ] --><br>
  <!-- [--><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="" style="background-position: -254px -131px;"></span></span><!-- ] -->
 <div class="city_change_jt" id="city_change_jt" style="position:relative;" onmouseover="showChooseCity();">
 <input type="hidden" name="cityCode" id="cityCode" value="${cityCode}">
  <a class="area-side" href="#" style="cursor:pointer;color:#ff6600" id="cityShow" onclick="aa('div_area',0)">
  <c:choose> 
  <c:when test="${'0792' == cityCode}">九江</c:when>
  <c:when test="${'0793' == cityCode}">上饶</c:when>
  <c:when test="${'0794' == cityCode}">抚州</c:when>
  <c:when test="${'0795' == cityCode}">宜春</c:when>
  <c:when test="${'0796' == cityCode}">吉安</c:when>
  <c:when test="${'0797' == cityCode}">赣州</c:when>
  <c:when test="${'0798' == cityCode}">景德镇</c:when>
  <c:when test="${'0799' == cityCode}">萍乡</c:when>
  <c:when test="${'0790' == cityCode}">新余</c:when>
  <c:when test="${'0701' == cityCode}">鹰潭</c:when>
  <c:when test="${'0791' == cityCode}">南昌</c:when>
  <c:otherwise>切换地区</c:otherwise>
  </c:choose>
  <img id="a_area" name="a_area" onclick="" src="${contextPath }/images/city_down.jpg" />]</a>
  </div>
   
  <!--隐藏层,地市列表 begin -->
  <div style="DISPLAY: none;position: absolute; z-index: 3;width: 220px" onmouseenter="showChooseCity();" id="div_area" name="div_area" class="city-show">
 
<H3>请选择地区</H3>
<li class="style2">
<a href="#" onclick="fuc_setcity_v3logo('南昌','0791');" style="cursor:hand;">南昌</a>
<a href="#" onclick="fuc_setcity_v3logo('九江','0792');" style="cursor:hand;">九江</a>
<a href="#" onclick="fuc_setcity_v3logo('上饶','0793');" style="cursor:hand;">上饶</a>
<a href="#" onclick="fuc_setcity_v3logo('抚州','0794');" style="cursor:hand;">抚州</a>
<a href="#" onclick="fuc_setcity_v3logo('宜春','0795');" style="cursor:hand;">宜春</a>
<a href="#" onclick="fuc_setcity_v3logo('吉安','0796');" style="cursor:hand;">吉安</a>
<a href="#" onclick="fuc_setcity_v3logo('赣州','0797');" style="cursor:hand;">赣州</a>


<a href="#" onclick="fuc_setcity_v3logo('景德镇','0798');" style="cursor:hand;">景德镇</a>
<a href="#" onclick="fuc_setcity_v3logo('萍乡','0799');" style="cursor:hand;">萍乡</a>
<a href="#" onclick="fuc_setcity_v3logo('新余','0790');" style="cursor:hand;">新余</a>
<a href="#" onclick="fuc_setcity_v3logo('鹰潭','0701');" style="cursor:hand;">鹰潭</a>
</li> 

  </div>
  </div>

------------------------------以下是js代码-----------------------------------------
function fuc_setcity_v3logo(cityName, cityCode)
{
var cityShow = document.getElementById("cityShow");
var cityCodeObj = document.getElementById("cityCode");
if (cityShow && cityCodeObj)
{
cityCodeObj.value = cityCode;
cityShow.innerHTML = "["+cityName+"<img id=\"a_area\" name=\"a_area\" src=\"${contextPath }/images/city_down.jpg\" />]";
document.getElementById("div_area").style.display="none";
}
}

function showChooseCity()
{
var cityShow = document.getElementById("city_change_jt");
var pos = GetObjPos(cityShow);
var l = document.getElementById("div_area");
l.style.left = pos.x;
l.style.top = pos.y + 12;
l.style.display="block";
}

function hideChooseCity(obj)
{
var cityShow = document.getElementById("div_area");
cityShow.style.display = "none";
}

function CPos(x, y)
{
  this.x = x;
  this.y = y;
}

function GetObjPos(ATarget)
{
  var target = ATarget;
  var pos = new CPos(target.offsetLeft, target.offsetTop);
   
  var target = target.offsetParent;
  while (target)
  {
  pos.x += target.offsetLeft;
  pos.y += target.offsetTop;
  target = target.offsetParent;
  }
   
  return pos;
}

[解决办法]
我正在看代码呢,谁知道你解决了。

热点排行