你来的这天,阳光很好,bug很少......

select选项框特效

 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8">
 5     <title></title>
 6 </head>
 7 <body>
 8 <select name="slt" id="slt" style="width: 100px"></select>
 9 <script src="js/jquery-1.11.3.js"></script>
10 <script>
11     var arr1 = ["A","B","C","D"];
12     var arr2 = ["+111","+222","+333","+444"];
13     function arr(){
14         $('#slt').html("");
15         for(var i= 0;i<arr1.length;i++){
16             //var ops= $("<option value="+i+">"+arr1[i]+""+arr2[i]+"</option>");
17             var ops= "<option value="+i+" id='d"+i+"'>"+arr1[i]+""+arr2[i]+"</option>";
18             $('#slt').append(ops);
19         };
20 
21 
22     };
23     arr();
24     var p=true;
25     var x =0;
26     $('#slt').unbind("click").click(function (e) {
27 
28         if(p){
29             x++;
30             p=false;
31             //$('#slt').unbind("click")
32             console.log(2)
33             e.stopPropagation()
34             $('#slt').html("")
35             arr();
36         }
37     })
38 
39     $('#slt').change(function(){
40 
41         //var slt = $('#slt').val();
42         var slt = $('#slt option:selected').html();
43 
44         console.log(slt)
45         var inx = slt.indexOf("+");
46 
47         var inn = slt.slice(inx);//+后面
48         var slc = slt.slice(0,inx);//+前面
49         //var slc = txt.slice(inx);
50         //$('#slt').text(slc);
51         console.log(slc);
52         //console.log(inn);
53        // var ops= "<option value='i'>"+arr1[i]+""+arr2[i]+"</option>";
54 
55         $('#slt option:selected').html(slc);
56         //console.log($(this).text())
57         if(x%2 == 0){
58             p=false;
59         }
60         if(x%2 == 1){
61             p=true;
62         }
63   });
66     //arr();
67 </script>
68 </body>
69 </html>

 

posted on 2016-05-15 23:49  Hardy-zh  阅读(379)  评论(0编辑  收藏  举报

导航