類比 html radio 的單選效果

來源:互聯網
上載者:User

:

 

 

 

代碼如下:

 

(jQuery版)

 

<html><br /><style><br />.unchecked{<br /> border: 1px solid gray;<br /> padding: 6px 6px 6px 6px;<br />}<br />.checked{<br /> border: 2px solid #c00;<br /> padding: 6px 6px 6px 6px;<br />}<br /></style><br /><script src="http://code.jquery.com/jquery-1.4.2.min.js" ></script><br /><script type="text/javascript"><br />var obj={<br /> colorSpan:"",<br /> sizeSpan:""<br />};<br />function change(span)<br />{<br /> $('span[name="'+$(span).attr('name')+'"]').each(function(){<br /> if(this.checked&&this!=span)<br /> {<br /> this.className="unchecked";<br /> this.checked=false;<br /> }<br /> });<br /> obj[$(span).attr('name')]=span.innerHTML;<br /> span.className="checked";<br /> span.checked=true;<br /> select();<br />}<br />function select()<br />{<br /> var html='';<br /> for(var i in obj)<br /> {<br /> if(obj[i]!='')<br /> {<br /> html+='<font color=orange>"'+ obj[i]+'"</font> 、';<br /> }<br /> }<br /> html='<b>已選擇:</b> '+html.slice(0,html.length-1);<br /> $('#resultSpan').html(html);</p><p>}<br /></script><br /><body><br /><br /><br /><div><br />顏色:  <span class='unchecked' name='colorSpan' checked='false' onclick='change(this);' >卡其格</span> <span class='unchecked' name='colorSpan' checked='false' onclick='change(this);' >黑白格</span><br /></div><br /><br /><br /><br /><br /><div><br />尺碼:  <span class='unchecked' name='sizeSpan' checked='false' onclick='change(this);' >S</span> <span class='unchecked' name='sizeSpan' checked='false' onclick='change(this);' >M</span> <span class='unchecked' name='sizeSpan' checked='false' onclick='change(this);' >L</span><br /></div><br /><br /><br /><br /><br /><div><br /><b>提示:</b>  <span id='resultSpan'></span><br /></div><br /></body><br /></html>

 

 

(純JS版)

 

<html><br /><style><br /> .unchecked<br /> {<br /> border: 1px solid gray;<br /> padding: 6px 6px 6px 6px;<br /> }<br /> .checked<br /> {<br /> border: 2px solid #c00;<br /> padding: 6px 6px 6px 6px;<br /> }<br /></style><br /><body><br /> <br /><br /> <div><br /> 顏色: <span class='unchecked' name='colorSpan'>卡其格</span> <span class='unchecked' name='colorSpan'><br /> 黑白格</span><br /> </div><br /> <br /><br /> <br /><br /> <div><br /> 尺碼: <span class='unchecked' name='sizeSpan'>S</span> <span class='unchecked' name='sizeSpan'><br /> M</span> <span class='unchecked' name='sizeSpan'>L</span><br /> </div><br /> <br /><br /> <br /><br /> <div><br /> <b>提示:</b> <span id='resultSpan'></span><br /> </div><br /></body><br /></html><br />

 

 

 

原帖地址:

 

http://topic.csdn.net/u/20100421/15/e431bfe0-f455-43f1-b460-8bf068ecf0b9.html

 

 

聯繫我們

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