| 
            <style> .c{ width:100px; height:25px; line-height:25px; text-align:center; border:1px solid #eee; margin:10px; float:left; font-size:12px; cursor:pointer } </style> </head> <body> <div class="c" id="c0">啤酒</div> <div class="c" id="c1">香烟</div> <div class="c" id="c2">饮料</div> <div class="c" id="c3">瓜子</div> <div class="c" id="c4">水果</div> <div class="c" id="c5">茶水</div> <input id="i" type="text" style="width:720px; height:25px; border:1px solid #ccc"/> <script> var x=["啤酒","香烟","饮料","瓜子","水果","茶水"]; var y=[]; function $(id){ return document.getElementById(id)}; for(var i=0,m=x.length;i<m;i++){  $("c"+i).onclick=(function(i){   return function(){    var s=y.join(",").indexOf(x[i]);   if(s>=0){   for(var r in y){    if(y[r]==x[i]){y.splice(r,1)}    }    }   else{    y.push(x[i])    }       $("i").value=y.join(" ");   }   })(i)    } </script> |