自己写的jQuery 左右选择框,大家多多指教!_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 自己写的jQuery 左右选择框,大家多多指教!

自己写的jQuery 左右选择框,大家多多指教!

 2014/6/25 13:53:03  super1234  程序员俱乐部  我要评论(0)
  • 摘要:Html代码<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN"><HTML><HEAD><TITLE>NewDocument</TITLE><METANAME="Generator"CONTENT="EditPlus"><METANAME="Author"CONTENT=""><METANAME="Keywords"CONTENT="">
  • 标签:大家 自己 jQuery
Html代码 javascripts/syntaxhighlighter/clipboard_new.swf" type="application/x-shockwave-flash">class%3D%22sel%22%20id%3D%22sel_left%22%3E%0A%09%09%09%3Coption%20value%3D%22a%22%3Eaaaaaaaaaaa%3C%2Foption%3E%0A%09%09%09%3Coption%20value%3D%22b%22%3Ebbbbbbbbbbb%3C%2Foption%3E%0A%09%09%09%3Coption%20value%3D%22c%22%3Eccccccccccc%3C%2Foption%3E%0A%09%09%09%3Coption%20value%3D%22d%22%3Eddddddddddd%3C%2Foption%3E%0A%09%09%09%3Coption%20value%3D%22e%22%3Eeeeeeeeeeee%3C%2Foption%3E%0A%09%09%20%20%3C%2Fselect%3E%0A%09%09%3C%2Ftd%3E%0A%09%09%3Ctd%3E%09%0A%09%09%09%3Cp%3E%3Cbutton%20class%3D%22btn%22%20id%3D%22btn_1%22%3E%26gt%3B%26gt%3B%20%3C%2Fbutton%3E%3C%2Fp%3E%0A%09%09%09%3Cp%3E%3Cbutton%20class%3D%22btn%22%20id%3D%22btn_2%22%3E%26gt%3B%3C%2Fbutton%3E%3C%2Fp%3E%0A%09%09%09%3Cp%3E%3Cbutton%20class%3D%22btn%22%20id%3D%22btn_3%22%3E%26lt%3B%3C%2Fbutton%3E%3C%2Fp%3E%0A%09%09%09%3Cp%3E%3Cbutton%20class%3D%22btn%22%20id%3D%22btn_4%22%3E%26lt%3B%26lt%3B%3C%2Fbutton%3E%3C%2Fp%3E%0A%09%09%09%0A%09%09%3C%2Ftd%3E%0A%09%09%3Ctd%3E%0A%09%09%09%20%3Cselect%20multiple%20class%3D%22sel%22%20id%3D%22sel_right%22%3E%0A%09%09%09%20%3Coption%20value%3D%22f%22%3Efffffffffff%3C%2Foption%3E%0A%09%09%09%20%3C%2Fselect%3E%0A%09%09%3C%2Ftd%3E%0A%09%3C%2Ftr%3E%0A%3C%2Ftable%3E%0A%20%3C%2FBODY%3E%0A%20%20%20%3Cscript%3E%0A%20%20%24(function()%7B%0A%09%24(%22%23sel_left%2C%23sel_right%22).bind(%22change%22%2CcheckBtn)%3B%0A%09%24(%22%23btn_1%2C%23btn_2%2C%23btn_3%2C%23btn_4%22).bind(%22click%22%2CclickBtn)%3B%0A%09checkBtn()%3B%0A%09%7D)%3B%0A%09%0A%09function%20checkBtn()%7B%0A%09%09jQuery(%22%23sel_left%3Eoption%22).length%20%3E%200%20%3F%20jQuery(%22%23btn_1%22).removeAttr(%22disabled%22)%20%3A%20jQuery(%22%23btn_1%22).attr(%22disabled%22%2C%22disabled%22)%3B%0A%09%09jQuery(%22%23sel_left%20option%3Aselected%22).length%20%3E%200%20%3F%20jQuery(%22%23btn_2%22).removeAttr(%22disabled%22)%20%3A%20jQuery(%22%23btn_2%22).attr(%22disabled%22%2C%22disabled%22)%3B%0A%09%09jQuery(%22%23sel_right%20option%3Aselected%22).length%20%3E%200%20%3F%20jQuery(%22%23btn_3%22).removeAttr(%22disabled%22)%20%3A%20jQuery(%22%23btn_3%22).attr(%22disabled%22%2C%22disabled%22)%3B%0A%09%09jQuery(%22%23sel_right%3Eoption%22).length%20%3E%200%20%3F%20jQuery(%22%23btn_4%22).removeAttr(%22disabled%22)%20%3A%20jQuery(%22%23btn_4%22).attr(%22disabled%22%2C%22disabled%22)%3B%0A%09%7D%0A%09%0A%09function%20clickBtn(e)%7B%0A%09%09if(%22btn_1%22%20%3D%3D%20e.target.id)%7B%0A%09%09%09jQuery(%22%23sel_left%3Eoption%22).appendTo(%22%23sel_right%22)%3B%0A%09%09%7Delse%20if(%22btn_2%22%20%3D%3D%20e.target.id)%7B%0A%09%09%09jQuery(%22%23sel_left%20option%3Aselected%22).appendTo(%22%23sel_right%22)%3B%0A%09%09%7Delse%20if(%22btn_3%22%20%3D%3D%20e.target.id)%7B%0A%09%09%09jQuery(%22%23sel_right%20option%3Aselected%22).appendTo(%22%23sel_left%22)%3B%0A%09%09%7Delse%20if(%22btn_4%22%20%3D%3D%20e.target.id)%7B%0A%09%09%09jQuery(%22%23sel_right%3Eoption%22).appendTo(%22%23sel_left%22)%3B%0A%09%09%7D%0A%09%09checkBtn()%3B%0A%09%7D%0A%20%20%3C%2Fscript%3E%0A%3C%2FHTML%3E%0A" />ways" /> 收藏代码
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
  2. <HTML>  
  3.  <HEAD>  
  4.   <TITLE> New Document </TITLE>  
  5.   <META NAME="Generator" CONTENT="EditPlus">  
  6.   <META NAME="Author" CONTENT="">  
  7.   <META NAME="Keywords" CONTENT="">  
  8.   <META NAME="Description" CONTENT="">  
  9.   <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>  
  10.   
  11.   <style>  
  12.   .sel{width:150px;height:200px;}  
  13.   .btn{width:50px;font-weight:bold;font-size:14px; }  
  14.   </style>  
  15.  </HEAD>  
  16.   
  17.  <BODY>  
  18.  <table>  
  19.     <tr>  
  20.         <td>  
  21.           <select multiple class="sel" id="sel_left">  
  22.             <option value="a">aaaaaaaaaaa</option>  
  23.             <option value="b">bbbbbbbbbbb</option>  
  24.             <option value="c">ccccccccccc</option>  
  25.             <option value="d">ddddddddddd</option>  
  26.             <option value="e">eeeeeeeeeee</option>  
  27.           </select>  
  28.         </td>  
  29.         <td>    
  30.             <p><button class="btn" id="btn_1">&gt;&gt; </button></p>  
  31.             <p><button class="btn" id="btn_2">&gt;</button></p>  
  32.             <p><button class="btn" id="btn_3">&lt;</button></p>  
  33.             <p><button class="btn" id="btn_4">&lt;&lt;</button></p>  
  34.               
  35.         </td>  
  36.         <td>  
  37.              <select multiple class="sel" id="sel_right">  
  38.              <option value="f">fffffffffff</option>  
  39.              </select>  
  40.         </td>  
  41.     </tr>  
  42. </table>  
  43.  </BODY>  
  44.    <script>  
  45.   $(function(){  
  46.     $("#sel_left,#sel_right").bind("change",checkBtn);  
  47.     $("#btn_1,#btn_2,#btn_3,#btn_4").bind("click",clickBtn);  
  48.     checkBtn();  
  49.     });  
  50.       
  51.     function checkBtn(){  
  52.         jQuery("#sel_left>option").length > 0 ? jQuery("#btn_1").removeAttr("disabled") : jQuery("#btn_1").attr("disabled","disabled");  
  53.         jQuery("#sel_left option:selected").length > 0 ? jQuery("#btn_2").removeAttr("disabled") : jQuery("#btn_2").attr("disabled","disabled");  
  54.         jQuery("#sel_right option:selected").length > 0 ? jQuery("#btn_3").removeAttr("disabled") : jQuery("#btn_3").attr("disabled","disabled");  
  55.         jQuery("#sel_right>option").length > 0 ? jQuery("#btn_4").removeAttr("disabled") : jQuery("#btn_4").attr("disabled","disabled");  
  56.     }  
  57.       
  58.     function clickBtn(e){  
  59.         if("btn_1" == e.target.id){  
  60.             jQuery("#sel_left>option").appendTo("#sel_right");  
  61.         }else if("btn_2" == e.target.id){  
  62.             jQuery("#sel_left option:selected").appendTo("#sel_right");  
  63.         }else if("btn_3" == e.target.id){  
  64.             jQuery("#sel_right option:selected").appendTo("#sel_left");  
  65.         }else if("btn_4" == e.target.id){  
  66.             jQuery("#sel_right>option").appendTo("#sel_left");  
  67.         }  
  68.         checkBtn();  
  69.     }  
  70.   </script>  
  71. </HTML>
发表评论
用户名: 匿名