CSS select樣式最佳化 含jquery代碼,cssjquery

來源:互聯網
上載者:User

CSS select樣式最佳化 含jquery代碼,cssjquery

CSS 下拉選擇菜單基本的CSS樣式不怎麼好看,通過一些簡單的樣式最佳化,可以得到如這樣的:

html結構如下:

<div class="sel_wrap">    <label>請選擇您所在的城市</label>    <select class="select" name="" id="c_city">        <option value="0">請選擇您所在的城市</option>        <option value="1">中山市</option>        <option value="2">太原市</option>        <option value="3">廣州市</option>    </select></div>

 

css樣式:

.sel_wrap{height:40px;background:#fff url(img/icons.png) no-repeat right -24px;color: #a1a1a1; font-size: 16px;border:1px solid #E4E4E4;cursor:pointer;position:relative;_filter:alpha(opacity=0);}.sel_wrap label{padding-left:10px;font-size:16px;z-index:2; color: #a1a1a1; line-height: 40px; height: 40px; display: block;}.sel_wrap .select{width:100%; height:40px; line-height:40px; z-index:4;position:absolute;top:0;left:0;margin:0;padding:0;opacity:0; *margin-top:12px; filter:alpha(opacity=0);cursor:pointer; font-size: 16px;}

 

jquery代碼:

$(".sel_wrap").on("change", function() {    var o;    var opt = $(this).find('option');    opt.each(function(i) {        if (opt[i].selected == true) {            o = opt[i].innerHTML;        }    })    $(this).find('label').html(o);});

這兒只是提供一種方法而已,當然前面文章中已經寫過用css3類比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.