123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Aisky-coffee</title>
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
-
- <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
-
- <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
-
- <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
-
- <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
- <style>
-
- .dropdown_item{
- width: 100%;
- }
- .dropdown_item>li:HOVER{
- background-color: #eee;
- cursor: pointer;
- }
- .dropdown_item>li {
- display: block;
- padding: 3px 10px;
- clear: both;
- font-weight: normal;
- line-height: 1.428571429;
- color: #333;
- white-space: nowrap;
- }
- .dropdown_item>li>.check_box{
- width: 18px;
- height: 18px;
- vertical-align: middle;
- margin: 0px;
- }
- .dropdown_item>li>span{
- vertical-align: middle;
- }
- .select_multiple .caret{
- border-top: 4px solid!important;
- border-bottom: 0;
- }
- </style>
- <script>
-
- $(document).on("click",".check_box",function(event){
- event.stopPropagation();
-
- var $selectTextDom=$(this).parent().parent("ul").siblings("button").children(".select_text");
-
- var $selectValDom=$(this).parent().parent("ul").siblings(".select_val");
-
- var isSelected=$selectTextDom[0].getAttribute("data-is-select");
- var selectText="";
- var selectVal=$selectValDom.val();
- var selected_text=$(this).siblings("span").text();
- var selected_val=$(this).val();
-
- if(isSelected=="true"){
- selectText=$selectTextDom.text();
- }
- if(selectText!=""){
- if(selectText.indexOf(selected_text)>=0){
- selectText=selectText.replace(selected_text,"").replace(",,",",");
- selectVal=selectVal.replace(selected_val,"").replace(",,",",");
-
- if(selectText.charAt(selectText.length - 1)==","){
-
- selectText=selectText.substring(0,selectText.length - 1);
- selectVal=selectVal.substring(0,selectVal.length - 1);
- }
- }else{
- selectText+=","+selected_text;
- selectVal+=","+selected_val;
- }
- }else{
- selectText=selected_text;
- selectVal=selected_val;
- }
- $selectTextDom.text(selectText);
- $selectValDom.val(selectVal);
- if(selectText==""){
- $selectTextDom.text("請選擇");
- $selectTextDom[0].setAttribute("data-is-select","false");
- }else{
- $selectTextDom[0].setAttribute("data-is-select","true");
- }
- })
- </script>
- </head>
- <body>
- <div class="dropup" style="position: relative;">
- <button class="btn btn-default dropdown-toggle form-control select_multiple" style="width: 20%;margin-left: 0px;" type="button" id="dropdownMenu21" data-toggle="dropdown">
- <span class="select_text" data-is-select="false">Dro pup</span>
- <span class="caret"></span>
- </button>
- <ul class="dropdown-menu dropdown_item" style="bottom: auto;">
- <li><input type="checkbox" class="check_box" value="aa" /> <span>Action</span></li>
- <li><input type="checkbox" class="check_box" value="bb"/> <span>Another action</span></li>
- <li><input type="checkbox" class="check_box" value="cc"/> <span>Something else here</span></li>
- <li><input type="checkbox" class="check_box" value="dd"/> <span>Separated link</span></li>
- </ul>
- <input type="hidden" name="" class="select_val"/>
- </div>
- <select>
-
-
-
-
-
-
-
-
- <option>red</option>
- </select>
- </body>
- </html>
|