日期:2014-05-17 浏览次数:20407 次
<html> <style> .unchecked{ border: 1px solid gray; padding: 5px; } .checked{ border: 2px solid #c00; padding: 5px; } </style> <script src="http://code.jquery.com/jquery-1.4.2.min.js" ></script> <script type="text/javascript"> var obj={ colorSpan:"", sizeSpan:"" }; function change(span) { $('span[name="'+$(span).attr('name')+'"]').each(function(){ if(this.checked&&this!=span) { this.className="unchecked"; this.checked=false; } }); obj[$(span).attr('name')]=span.innerHTML; span.className="checked"; span.checked=true; select(); } function select() { var html=''; for(var i in obj) { if(obj[i]!='') { html+='<font color=orange>"'+ obj[i]+'"</font> 、'; } } html='<b> 已选择:</b> '+html.slice(0,html.length-1); $('#resultSpan').html(html); } </script> <body> <br /> <div> 颜色: <span class='unchecked' name='colorSpan' checked='false' onclick='change(this);' colorId="1">卡其格</span> <span class='unchecked' name='colorSpan' checked='false' onclick='change(this);' colorId="2" >黑白格</span> </div> <br /> <br /> <div> 尺码: <span class='unchecked' name='sizeSpan' checked='false' onclick='change(this);' sizeId="1">S</span> <span class='unchecked' name='sizeSpan' checked='false' onclick='change(this);' sizeId="2">M</span> <span class='unchecked' name='sizeSpan' checked='false' onclick='change(this);' sizeId="3">L</span> </div> <br /> <br /> <div> <b>提示:</b> <span id='resultSpan'></span> </div> <div> </div> </body> </html>