Jquery實現彈出選擇框選擇後返回,支援多級分類,jquery

來源:互聯網
上載者:User

Jquery實現彈出選擇框選擇後返回,支援多級分類,jquery

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  <title>選擇收件者</title>  <script src="../jquery-1.11.1.min.js" type="text/javascript"></script>  <script src="friend.js" type="text/javascript"></script> </head> <body>收件者:<input type="text" name="my-name" id="my-name" value="請選擇收件者" onclick="pop()" />           <input type="hidden" name="my-value" id="my-value" />    <!--alert layer--><div id="choose-box-wrapper">  <div id="choose-box"><div id="choose-box-title"><span>選擇好友</span></div><div id="choose-a-class"></div><div>            <ul id="choose-a-item">            </ul></div><div id="choose-box-bottom">            <input type="button" onclick="doSelect()" value="確定" />  <input type="button" onclick="hide()" value="關閉" /></div>  </div></div>    <!--alert layer-->    <script type="text/javascript">//快顯視窗function pop(){//將視窗置中makeCenter();//初始化分類列表initLayerClass();//預設情況下, 給第一個分類添加choosen樣式$('[class-id="1"]').addClass('choosen');//初始化ITEM列表initItemList(1);}//隱藏視窗function hide() {    $('#choose-box-wrapper').css("display", "none");}    //擷取選擇值function doSelect() {    var list = $(".class-item-ck");    var text = "";    var value = "";    list.each(function () {        if ($(this).is(':checked')) {            text += $(this).attr("item-name") + ";";            value += $(this).attr("item-id");        };    });    $('#my-name').val('').val(text);    $('#my-value').val('').val(value);    //關閉彈窗    hide();    };function initLayerClass(){//原先的分類列表清空$('#choose-a-class').html('');for (i = 0; i < itemList.length; i++) {    $('#choose-a-class').append('<a class="class-item" class-id="' + itemList[i].id + '">' + itemList[i].name + '</a>');}//添加分類清單項目的click事件$('.class-item').bind('click', function () {    var item = $(this);    var classid = item.attr('class-id');    var choosenItem = item.parent().find('.choosen');    if (choosenItem) {        $(choosenItem).removeClass('choosen');    }    item.addClass('choosen');    //更新列表    initItemList(classid);});}function initItemList(classid){//原先列表清空$('#choose-a-item').html('');var mitems = itemList[classid - 1].items;for (i = 0; i < mitems.length; i++) {    var html = '<li class="itemli">';    html += '<a class="mdata-item" item-id="' + mitems[i].id + '">' + mitems[i].name + '</a>';    html += '<input type="checkbox" class="class-item-ck" item-id="' + mitems[i].id + '" item-name="' + mitems[i].name + '" />';    html += '</li>';    $('#choose-a-item').append(html);}//添加詳細清單項目的click事件$('.mdata-item').bind('click', function(){var item=$(this);//更新選擇文字框中的值$('#my-name').val(item.text());//關閉彈窗hide();});}function makeCenter(){$('#choose-box-wrapper').css("display","block");$('#choose-box-wrapper').css("position","absolute");$('#choose-box-wrapper').css("top", Math.max(0, (($(window).height() - $('#choose-box-wrapper').outerHeight()) / 2) + $(window).scrollTop()) + "px");$('#choose-box-wrapper').css("left", Math.max(0, (($(window).width() - $('#choose-box-wrapper').outerWidth()) / 2) + $(window).scrollLeft()) + "px");}  </script>  <style type="text/css">#choose-box-wrapper{width: 652px;background-color:#000;filter:alpha(opacity=50);background-color: rgba(0, 0, 0, 0.5);padding:10px;border-radius:5px;display:none;}#choose-box{border: 1px solid #005EAC;width:650px;background-color:white;}#choose-box-title{background:#3777BC;color: white;padding: 4px 10px 5px;font-size: 14px;font-weight: 700;margin: 0;}#choose-box-title span{font-family: Tahoma, Verdana, STHeiTi, simsun, sans-serif;}#choose-a-class, #choose-a-item{margin:5px 8px 10px 8px;border: 1px solid #C3C3C3;}#choose-a-class a{display:inline-block;height: 18px;line-height: 18px;color:#005EAC;text-decoration: none;font-size: 9pt;font-family: Tahoma, Verdana, STHeiTi, simsun, sans-serif;margin:2px 5px;padding: 5px;text-align: center;}#choose-a-class a:hover{text-decoration: none;cursor:pointer;}#choose-a-class .choosen{background-color: #005EAC;color:white;}#choose-a-item{overflow-x: hidden;overflow-y: auto;height: 200px;}#choose-a-item a{height: 18px;line-height: 18px;color:#005EAC;text-decoration: none;font-size: 9pt;font-family: Tahoma, Verdana, STHeiTi, simsun, sans-serif;float: left;padding:2px 5px 2px 5px;margin: 4px;padding-left:10px;background:url(2012072500060712.gif) no-repeat 0 9px;}#choose-a-item a:hover{background-color:#005EAC;color:white;cursor:pointer;}#choose-a-item .itemli{    width:100px;     list-style:none;     float:left;}#choose-a-item .class-item-ck{    margin-top:10px;    display:inline;}#choose-box-bottom{background: #F0F5F8;padding: 8px;text-align: right;border-top: 1px solid #CCC;height:40px;}#choose-box-bottom input{vertical-align: middle;text-align: center;background-color:#005EAC;color:white;border-top: 1px solid #B8D4E8;border-left: 1px solid #B8D4E8;border-right: 1px solid #114680;border-bottom: 1px solid #114680;cursor: pointer;width: 60px;height: 25px;margin-top: 6px;margin-right: 6px;}  </style> </body></html>
var itemList = [{    "id": 1,    "items": [{        "id": 1001,        "name": "張三1"    },    {        "id": 1002,        "name": "李四1"    },    {        "id": 1003,        "name": "王五1"    },    {        "id": 1004,        "name": "趙六1"    },    {        "id": 1005,        "name": "趙七1"    }],    "name": "我的同學"},{    "id": 2,    "items": [{        "id": 1001,        "name": "張三2"    },    {        "id": 1002,        "name": "李四2"    },    {        "id": 1003,        "name": "王五2"    },    {        "id": 1004,        "name": "趙六2"    },    {        "id": 1005,        "name": "趙七2"    }],    "name": "我的同事"}]


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.