js解決select下拉選不中問題
更新時間:2014年10月14日 16:41:22 投稿:whsnow
當(dāng)事件mouseover中出現(xiàn)select下拉框時,select下拉是選不中的,下面有個不錯的解決方法,大家可以看看
當(dāng)事件mouseover中出現(xiàn)select下拉框時,select下拉是選不中的,解決辦法:
var o = e.relatedTarget || e.toElement;//判斷下移動到的對象,移動到option上ie下是null,firefox等為undefined。。
if (!o) return;//為option退出不隱藏
完整代碼案例為:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<style type="text/css">
*{margin:0;padding:0;list-style:none;border:0;}
.pop_blue{ position:absolute; cursor:pointer; padding:10px;}
.pop_blue span{ display:inline-block; width:24px; height:32px; background: url(../images/pop_blue.png) no-repeat;}
.map_xf .rud1{width:210px; position:absolute;border:1px solid #ddd; display:none; background-color:#fff;padding:17px 25px;}
.map_xf .rud1 li{margin:0 0 8px;}
.map_xf .rud1 input,.map_xf .rud1 select{height:22px;}
</style>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function(){
$('.pop_blue').hover(
function(){
$(this).find('.rud1').show();
$(this).css("z-index","9999");
},
function(e){
var o = e.relatedTarget || e.toElement;//判斷下移動到的對象,移動到option上ie下是null,firefox等為undefined。。
if (!o) return;//為option退出不隱藏
$(this).find('.rud1').hide();
$(this).css("z-index","0");
}
)
})
</script>
</head>
<body>
<div style="position:relative;width:100px;height:100px">
<div class="pop_blue" style="top:0px; left:0;"> <span>鼠標(biāo)移上</span><i></i>
<div class="rud1 font12" style="top:10px;left:40px; display:none;padding:50px;background:blue;">
<ul>
<li>
<select class="w100" id="dan">
<option value="選擇單元" selected="">選擇單元</option>
<option value="選擇單元" selected="">選擇單元1</option>
<option value="選擇單元" selected="">選擇單元2</option>
<option value="選擇單元" selected="">選擇單元3</option>
<option value="選擇單元" selected="">選擇單元4</option>
</select>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>

當(dāng)鼠標(biāo)移上時就不會出現(xiàn)選不中select的情況了。
相關(guān)文章
javascript解析xml實現(xiàn)省市縣三級聯(lián)動的方法
這篇文章主要介紹了javascript解析xml實現(xiàn)省市縣三級聯(lián)動的方法,涉及javascript針對節(jié)點的操作與XML文件解析的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
利用JavaScript實現(xiàn)簡單的網(wǎng)頁時鐘
這篇文章主要介紹了利用JavaScript實現(xiàn)簡單的網(wǎng)頁時鐘,主要使用了js的日期對象,實現(xiàn)的時候先創(chuàng)建一個日期對象,并進(jìn)行網(wǎng)頁布局,對時間獲取之后將時間填入對應(yīng)的標(biāo)簽內(nèi)。然后使用多線程實現(xiàn)時鐘的變動,需要的朋友可以參考一下2022-02-02

