js解決select下拉問題,jsselect下拉

來源:互聯網
上載者:User

js解決select下拉問題,jsselect下拉

當事件mouseover中出現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>無標題文檔</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>滑鼠移上</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>
當滑鼠移上時就不會出現選不中select的情況了。


js動態刪除select下拉式清單問題

<html>
<head>
<title></title>
</head>
<body>
<script>
<!--
var num;//用於標識添加了幾個select,在後面的頁面用到
num=1;
var objPad;
function addSelect(str)
{
objPad = document.getElementById("pad");
if(str=="del"){
num=1;
//objPad.removeAllChild();
//objPad.innerHTML="";
var selectobj=document.getElementById("pad").getElementsByTagName("select");
var i=selectobj.length;
if(i>0)
{
objPad.removeChild(selectobj[i-1]);
objPad.removeChild(document.getElementById("pad").getElementsByTagName("br")[i-1]);
}
}
else
{
var s= new Array();
s=str.split(",")
var sel = "<select name='ksbj"+num+"'>"
for(var i=0;i<s.length;i++)
{
sel = sel+"<option value='"+s[i]+"'>"+s[i]+"</option>";
}
sel=sel+"</select><br />"
objPad.innerHTML = objPad.innerHTML+sel;
num = num+1;
}
}
function returnnum()
{
num1=num-1
var objPad = document.getElementById("pad");
sel="<input type='hidden' name='cs' value='"+num1+"' />"
objPad.innerHTML = objPad.innerHTML+sel;
}
-->
</script>
<input type="button" value="添加班級" onClick="addSelect('1,2,3')" />
<input type="butto......餘下全文>>
 
js select 選中問題,急

總有一總用的上
document.getElementById("Select1").value = "2";
//$("#Select1").val("2");//jquery

<select id="Select1">
<option value="0">x</option>
<option value="1" selected="selected">y</option>
<option value="2">z</option>
</select>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.