欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

jQuery获取radio值,jquery获取表单元素值

shiping1 的头像
  1. jQuery获取Radio选择的Value值:  
  2.   
  3. 1. $("input[name='radio_name'][checked]").val();  //选择被选中Radio的Value值  
  4. 2. $("#text_id").focus(function(){//code...});  //事件 当对象text_id获取焦点时触发  
  5. 3. $("#text_id").blur(function(){//code...});  //事件 当对象text_id失去焦点时触发  
  6. 4. $("#text_id").select();  //使文本框的Vlaue值成选中状态  
  7. 5. $("input[name='radio_name'][value='要中Radio的Value值']").attr("checked",true);   jQuery获取CheckBox选择的Value  
  8.   
  9. 语法解释:  
  10. 1. $("input[name='checkbox_name'][checked]");  //选择被选中CheckBox元素的集合 如果你想得到Value值,你需要遍历  
  11. 2. $($("input[name='checkbox_name'][checked]")).each(function(){arrChk+=this.value + ',';});  //遍历被选中CheckBox元素的集合 得到Value值  
  12. 3. $("#checkbox_id").attr("checked");  //获取一个CheckBox的状态(有没有被选中,返回true/false)  
  13. 4. $("#checkbox_id").attr("checked",true);  //设置一个CheckBox的状态为选中(checked=true)  
  14. 5. $("#checkbox_id").attr("checked",false);  //设置一个CheckBox的状态为不选中(checked=false)  
  15. 6. $("input[name='checkbox_name']").attr("checked",$("#checkbox_id").attr("checked"));   
  16.   
  17. 7. $("#text_id").val().split(",");  //将Text的Value值以','分隔 返回一个数组  
  18.   
  19.    
  20.   
  21. jQuery--checkbox全选/取消全选  
  22.   
  23. 用JavaScript使页面上的一组checkbox全选/取消全选,逻辑很简单,实现代码也没有太难的语法。但使用jQuery实现则更简单,代码也很简洁,精辟!  
  24. <input type="checkbox" name="chk_list" id="chk_list_1" value="1" />1<br />  
  25. <input type="checkbox" name="chk_list" id="chk_list_2" value="2" />2<br />  
  26. <input type="checkbox" name="chk_list" id="chk_list_3" value="3" />3<br />  
  27. <input type="checkbox" name="chk_list" id="chk_list_4" value="4" />4<br />  
  28. <input type="checkbox" name="chk_all" id="chk_all" />全选/取消全选  
  29. <script type="text/javascript">  
  30.   
  31. $("#chk_all").click(function() {  $("input[name='chk_list']").attr("checked",$(this).attr("checked"));});  
  32. </script>  
  33.   
  34.   
  35. jQuery.attr  获取/设置对象的属性值,如:  
  36.   
  37. $("input[name='chk_list']").attr("checked");     //读取所有name为'chk_list'对象的状态(是否选中)  
  38.   
  39. $("input[name='chk_list']").attr("checked",true);      //设置所有name为'chk_list'对象的checked为true  
  40.   
  41. 再如:  
  42.   
  43. $("#img_1").attr("src","test.jpg");    //设置ID为img_1的<img>src的值为'test.jpg'  
  44. $("#img_1").attr("src");     //读取ID为img_1的<img>src值  
  45.   
  46.    
  47.   
  48.  下面的代码是获取上面实例中选中的checkbox的value值:  
  49. <script type="text/javascript"> //获取到所有name为'chk_list'并选中的checkbox(集合)     
  50.   
  51.  var arrChk=$("input[name='chk_list]:checked");    //遍历得到每个checkbox的value值  
  52.   
  53.     for (var i=0;i<arrChk.length;i++){     alert(arrChk[i].value); }  
  54. </script>  
  55.   
  56. <script type="text/javascript">  
  57.   
  58.    var arrChk=$("input[name='chk_list']:checked"); $(arrChk).each(function() {   window.alert(this.value);  }); });</script>  
  59.   
  60.    
  61.   
  62. jQuery-对Select的操作集合[终结篇]  
  63.   
  64. jQuery获取Select选择的Text和Value:  
  65.   
  66. 语法解释:  
  67. 1. $("#select_id").change(function(){//code...});   //为Select添加事件,当选择其中一项时触发  
  68. 2. var checkText=$("#select_id").find("option:selected").text();  //获取Select选择的Text  
  69. 3. var checkValue=$("#select_id").val();  //获取Select选择的Value  
  70. 4. var checkIndex=$("#select_id ").get(0).selectedIndex;  //获取Select选择的索引值  
  71. 5. var maxIndex=$("#select_id option:last").attr("index");  //获取Select最大的索引值   
  72. jQuery设置Select选择的Text和Value:  
  73. 语法解释:  
  74. 1. $("#select_id ").get(0).selectedIndex=1;  //设置Select索引值为1的项选中  
  75. 2. $("#select_id ").val(4);   //设置Select的Value值为4的项选中  
  76. 3. $("#select_id option[text='jQuery']").attr("selected", true);   //设置Select的Text值为jQuery的项选中  
  77.   
  78. jQuery添加/删除Select的Option项:  
  79.   
  80.  点击一次,Select将追加一个Option  
  81.  点击将在Select第一个位置插入一个Option  
  82.  点击将删除Select中索引值最大Option(最后一个)  
  83. 1. $("#select_id").append("<option value='Value'>Text</option>");  //为Select追加一个Option(下拉项)  
  84. 2. $("#select_id").prepend("<option value='0'>请选择</option>");  //为Select插入一个Option(第一个位置)  
  85. 3. $("#select_id option:last").remove();  //删除Select中索引值最大Option(最后一个)  
  86. 4. $("#select_id option[index='0']").remove();  //删除Select中索引值为0的Option(第一个)  
  87. 5. $("#select_id option[value='3']").remove();  //删除Select中Value='3'的Option  
  88. 5. $("#select_id option[text='4']").remove();  //删除Select中Text='4'的Option  
  89.   
  90.    
  91.   
  92. JQUERY获取text,areatext,radio,checkbox,select值  
  93.   
  94.    
  95.   
  96. jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关   
  97. 获取一组radio被选中项的值   
  98. var item = $('input[@name=items][@checked]').val();   
  99. 获取select被选中项的文本   
  100. var item = $("select[@name=items] option[@selected]").text();   
  101. select下拉框的第二个元素为当前选中值   
  102. $('#select_id')[0].selectedIndex = 1;   
  103. radio单选组的第二个元素为当前选中值   
  104. $('input[@name=items]').get(1).checked = true;   
  105. 获取值:   
  106. 文本框,文本区域:$("#txt").attr("value");   
  107. 多选框checkbox:$("#checkbox_id").attr("value");   
  108. 单选组radio:   $("input[@type=radio][@checked]").val();   
  109. 下拉框select: $('#sel').val();   
  110. 控制表单元素:   
  111. 文本框,文本区域:$("#txt").attr("value",'');//清空内容   
  112.                  $("#txt").attr("value",'11');//填充内容   
  113. 多选框checkbox: $("#chk1").attr("checked",'');//不打勾   
  114.                  $("#chk2").attr("checked",true);//打勾   
  115.                  if($("#chk1").attr('checked')==undefined) //判断是否已经打勾   
  116.   
  117. 单选组radio:    $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项   
  118. 下拉框select:   $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项   
  119.                 $("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option   
  120.                 $("#sel").empty();//清空下拉框  
  121.   
  122. ----------------------------------------------  
  123.   
  124. //遍历option和添加、移除option  
  125. function changeShipMethod(shipping){  
  126. var len = $("select[@name=ISHIPTYPE] option").length  
  127. if(shipping.value != "CA"){  
  128. $("select[@name=ISHIPTYPE] option").each(function(){  
  129. if($(this).val() == 111){  
  130. $(this).remove();  
  131. }  
  132. });  
  133. }else{$("<option value='111'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]"));}}  
  134.   
  135.   
  136. //取得下拉選單的選取值  
  137.   
  138. $(#testSelect option:selected').text();  
  139. 或$("#testSelect").find('option:selected').text();  
  140. 或$("#testSelect").val();  
  141. ************************************************************  
  142. 记性不好的可以收藏下:  
  143. 1,下拉框:  
  144.   
  145. var cc1 = $(".formc select[@name='country'] option[@selected]").text(); //得到下拉菜单的选中项的文本(注意中间有空格)  
  146. var cc2 = $('.formc select[@name="country"]').val(); //得到下拉菜单的选中项的值  
  147. var cc3 = $('.formc select[@name="country"]').attr("id"); //得到下拉菜单的选中项的ID属性值  
  148. $("#select").empty();//清空下拉框//$("#select").html('');  
  149. $("<option value='1'>1111</option>").appendTo("#select")//添加下拉框的option  
  150.   
  151. 稍微解释一下:  
  152. 1.select[@name='country'] option[@selected] 表示具有name 属性,  
  153. 并且该属性值为'country' 的select元素 里面的具有selected 属性的option 元素;  
  154. 可以看出有@开头的就表示后面跟的是属性。  
  155.   
  156. 2,单选框:  
  157. $("input[@type=radio][@checked]").val(); //得到单选框的选中项的值(注意中间没有空格)  
  158. $("input[@type=radio][@value=2]").attr("checked",'checked'); //设置单选框value=2的为选中状态.(注意中间没有空格)  
  159.   
  160. 3,复选框:  
  161. $("input[@type=checkbox][@checked]").val(); //得到复选框的选中的第一项的值  
  162. $("input[@type=checkbox][@checked]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出  
  163. alert($(this).val());  
  164. });  
  165.   
  166. $("#chk1").attr("checked",'');//不打勾  
  167. $("#chk2").attr("checked",true);//打勾  
  168. if($("#chk1").attr('checked')==undefined){} //判断是否已经打勾  
  169. 当然jquery的选择器是强大的. 还有很多方法.  
  170.   
  171. <script src="jquery-1.2.1.js" type="text/javascript"></script>  
  172. <script language="javascript" type="text/javascript">  
  173. $(document).ready(function(){  
  174. $("#selectTest").change(function()  
  175. {//alert("Hello");//alert($("#selectTest").attr("name"));//$("a").attr("href","xx.html");//window.location.href="xx.html";  
  176. //alert($("#selectTest").val());  
  177. alert($("#selectTest option[@selected]").text());  
  178. $("#selectTest").attr("value""2");  
  179.   
  180. });  
  181. });  
  182. </script>  
  183.   
  184.   
  185. <a href="#">aaass</a>  
  186.   
  187. <!--下拉框-->  
  188. <select id="selectTest" name="selectTest">  
  189. <option value="1">11</option><option value="2">22</option><option value="3">33</option>  
  190. <option value="4">44</option><option value="5">55</option><option value="6">66</option>  
  191. </select>  
  192. jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关获取一组radio被选中项的值  
  193. var item = $('input[@name=items][@checked]').val();  
  194. 获取select被选中项的文本  
  195. var item = $("select[@name=items] option[@selected]").text();  
  196. select下拉框的第二个元素为当前选中值  
  197. $('#select_id')[0].selectedIndex = 1;  
  198. radio单选组的第二个元素为当前选中值  
  199. $('input[@name=items]').get(1).checked = true;  
  200. 获取值:  
  201. 文本框,文本区域:$("#txt").attr("value");  
  202. 多选框checkbox:$("#checkbox_id").attr("value");  
  203. 单选组radio: $("input[@type=radio][@checked]").val();  
  204. 下拉框select: $('#sel').val();  
  205. 控制表单元素:  
  206. 文本框,文本区域:$("#txt").attr("value",'');//清空内容  
  207. $("#txt").attr("value",'11');//填充内容  
  208. 多选框checkbox: $("#chk1").attr("checked",'');//不打勾  
  209. $("#chk2").attr("checked",true);//打勾  
  210. if($("#chk1").attr('checked')==undefined) //判断是否已经打勾  
  211. 单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项  
  212. 下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项  
  213. $("<optionvalue='1'>1111</option><optionvalue='2'>2222</option>").appendTo("#sel")//添加下拉框的option  
  214. $("#sel").empty();//清空下拉框  
  215.   
  216. 获取一组radio被选中项的值  
  217. var item = $('input[@name=items][@checked]').val();  
  218. 获取select被选中项的文本  
  219. var item = $("select[@name=items] option[@selected]").text();  
  220. select下拉框的第二个元素为当前选中值  
  221. $('#select_id')[0].selectedIndex = 1;  
  222. radio单选组的第二个元素为当前选中值  
  223. $('input[@name=items]').get(1).checked = true;  
  224. 获取值:  
  225. 文本框,文本区域:$("#txt").attr("value");  
  226. 多选框checkbox:$("#checkbox_id").attr("value");  
  227. 单选组radio: $("input[@type=radio][@checked]").val();  
  228. 下拉框select: $('#sel').val();  
  229. 控制表单元素:  
  230. 文本框,文本区域:$("#txt").attr("value",'');//清空内容  
  231. $("#txt").attr("value",'11');//填充内容  
  232. 多选框checkbox: $("#chk1").attr("checked",'');//不打勾  
  233. $("#chk2").attr("checked",true);//打勾  
  234. if($("#chk1").attr('checked')==undefined) //判断是否已经打勾  
  235. 单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项  
  236. 下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项  
  237. $("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option  
  238. $("#sel").empty();//清空下拉框  
  239.   
  240. jQuery取得select选中的值  
  241.   
  242. 记录一下。  
  243.   
  244. 本来以为jQuery("#select1").val();是取得选中的值,  
  245.   
  246. 那么jQuery("#select1").text();就是取得的文本。  
  247.   
  248. 这是不正确的,正确做法是:  
  249.   
  250. jQuery("#select1  option:selected").text();  
  251.   
  252.    
  253.   
  254. 两个select之间option的互相添加操作(jquery实现)  
  255.   
  256.    
  257.   
  258. 两个select,将其中一个select选中的选项添加到另一个select中,或者点击全部添加按钮将所有的option都添加过去.  
  259. 自己写了一个很简单的jquery插件,在页面中调用其中的函数就可实现.  
  260. 插件源代码(listtolist.js):  
  261.   
  262. Js代码  
  263.   
  264. /**   
  265.   
  266. fromid:源list的id.   
  267.   
  268. toid:目标list的id.   
  269.   
  270. moveOrAppend参数("move"或者是"append"):   
  271.   
  272. move -- 源list中选中的option会删除.源list中选中的option移动到目标list中,若目标list中已存在则该option不添加.   
  273.   
  274. append -- 源list中选中的option不会删除.源list中选中的option添加到目标list的后面,若目标list中已存在则该option不添加.   
  275.   
  276.    
  277.   
  278. isAll参数(true或者false):是否全部移动或添加   
  279.   
  280. */    
  281.   
  282. jQuery.listTolist = function(fromid,toid,moveOrAppend,isAll) {    
  283.   
  284.     if(moveOrAppend.toLowerCase() == "move") {  //移动    
  285.   
  286.         if(isAll == true) { //全部移动    
  287.   
  288.             $("#"+fromid+" option").each(function() {    
  289.   
  290.                 //将源list中的option添加到目标list,当目标list中已有该option时不做任何操作.    
  291.   
  292.                 $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  293.   
  294.             });    
  295.   
  296.             $("#"+fromid).empty();  //清空源list    
  297.   
  298.         }    
  299.   
  300.         else if(isAll == false) {    
  301.   
  302.             $("#"+fromid+" option:selected").each(function() {    
  303.   
  304.                 //将源list中的option添加到目标list,当目标list中已有该option时不做任何操作.    
  305.   
  306.                 $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  307.   
  308.                 //目标list中已经存在的option并没有移动,仍旧在源list中,将其清空.    
  309.   
  310.                 if($("#"+fromid+" option[value="+$(this).val()+"]").length > 0) {    
  311.   
  312.                     $("#"+fromid).get(0)    
  313.   
  314.                     .removeChild($("#"+fromid+" option[value="+$(this).val()+"]").get(0));    
  315.   
  316.                 }    
  317.   
  318.             });    
  319.   
  320.         }    
  321.   
  322.     }    
  323.   
  324.     else if(moveOrAppend.toLowerCase() == "append") {    
  325.   
  326.         if(isAll == true) {    
  327.   
  328.             $("#"+fromid+" option").each(function() {    
  329.   
  330.                 $("<option></option>")    
  331.   
  332.                 .val($(this).val())    
  333.   
  334.                 .text($(this).text())    
  335.   
  336.                 .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  337.   
  338.             });    
  339.   
  340.         }    
  341.   
  342.         else if(isAll == false) {    
  343.   
  344.             $("#"+fromid+" option:selected").each(function() {    
  345.   
  346.                 $("<option></option>")    
  347.   
  348.                 .val($(this).val())    
  349.   
  350.                 .text($(this).text())    
  351.   
  352.                 .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  353.   
  354.             });    
  355.   
  356.         }    
  357.   
  358.     }    
  359.   
  360. };    
  361.   
  362. /**   
  363.   
  364. 功能大体同上("move").   
  365.   
  366. 不同之处在于当源list中的选中option在目标list中存在时,源list中的option不会删除.   
  367.   
  368.    
  369.   
  370. isAll参数(true或者false):是否全部移动或添加   
  371.   
  372. */    
  373.   
  374. jQuery.list2list = function(fromid,toid,isAll) {    
  375.   
  376.     if(isAll == true) {    
  377.   
  378.         $("#"+fromid+" option").each(function() {    
  379.   
  380.             $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  381.   
  382.         });    
  383.   
  384.     }    
  385.   
  386.     else if(isAll == false) {    
  387.   
  388.         $("#"+fromid+" option:selected").each(function() {    
  389.   
  390.             $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  391.   
  392.         });    
  393.   
  394.     }    
  395.   
  396. };    
  397.   
  398. <script type="text/javascript">  
  399.    jQuery(function($)      
  400. {         //获取select文本和值       
  401. $("#submitBut").click(function(){     //注意空格      
  402.     //var strText = $("select[@name=fselect] option[@selected]").text();      
  403.      // var strValue = $("select[@name=fselect] option[@selected]").val();      
  404.       //alert(strText + ":" + strValue);      
  405.        //选中值为t3项     
  406.    $("#fselect").attr("value""t3");     //选中第二项     
  407.    $('#fselect')[0].selectedIndex = 1;     
  408.      alert($("#fselect")[0].length);      
  409.    });      
  410.       //select改变时获取当前选项的值和文本      
  411.    $("#fselect").change(function(){      //获取总的选项      
  412.    //alert($(this)[0].length);      
  413. //获取的所有的文本       var strText = $(this).text();      
  414.       //获取当前选中值     var strValue = $(this).val();      
  415.  //alert(strText + ":" + strValue);      
  416.       //选中值为t3项    //选中第二项      
  417.    //$(this)[0].selectedIndex = 3;       //$(this).attr("value""t3");       / /$("#fselect")[0].options[2].selected = true;      
  418.       //获得当前选中的文本      
  419.    //显示索引为2的文本      
  420.    var nCurrent = $(this)[0].selectedIndex;      
  421.       alert($("#fselect")[0].options[nCurrent].text);      
  422.       alert(strValue);      
  423.    });      
  424.          
  425.    //增加select      
  426.    $("#add").click(function(){      
  427.      var nLength = $("#fselect")[0].length;      
  428.      var option = document.createElement("option");;      
  429.      option.text = "Text" + (nLength+1).toString();      
  430.      option.value = "t" + (nLength+1).toString();      
  431.      $("#fselect")[0].options.add(option);      
  432.      //$("#fselect").addOption("Text" + (nLength+1).toString(), "t" + (nLength+1).toString(), true);      
  433.    });            //清空select      
  434.    $("#clear").click(function(){      
  435.      $("#fselect").empty();      
  436.    });       //清空一项      
  437. $("#remove").click(function(){      
  438.      var index = $("#fselect")[0].selectedIndex;      
  439.      //$("#fselect")[0].remove(index);      
  440.      $("#fselect")[0].options[index] = null;      
  441.    });      
  442. })      
  443. </script>  
  444.   
  445. 其他有关select的取值或赋值方式:  
  446. 获取select被选中项的文本  
  447. var item = $("select[@name= stsoft] option[@selected]").text();  
  448. select下拉框的第二个元素为当前选中值  
  449. $('#stsoft')[0].selectedIndex = 1;  
  450. 获取value值  
  451. $('#stsoft').val();  
  452. 设置value=1的项目为当前选中项  
  453. $("#stsoft").attr("value",“1”);  
  454. $('#stsoft').val(“1”);  
  455.   
  456. Js代码  
  457.   
  458.      /**   
  459.      fromid:源list的id.   
  460.      toid:目标list的id.   
  461.      moveOrAppend参数("move"或者是"append"):   
  462.      move -- 源list中选中的option会删除.源list中选中的option移动到目标list中,若目标list中已存在则该option不添加.   
  463.      append -- 源list中选中的option不会删除.源list中选中的option添加到目标list的后面,若目标list中已存在则该option不添加.   
  464.         
  465.      isAll参数(true或者false):是否全部移动或添加   
  466.      */    
  467.  jQuery.listTolist = function(fromid,toid,moveOrAppend,isAll) {    
  468.      if(moveOrAppend.toLowerCase() == "move") {  //移动    
  469.          if(isAll == true) { //全部移动    
  470.              $("#"+fromid+" option").each(function() {    
  471.                  //将源list中的option添加到目标list,当目标list中已有该option时不做任何操作.    
  472.                  $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  473.              });    
  474.              $("#"+fromid).empty();  //清空源list    
  475.          }    
  476.          else if(isAll == false) {    
  477.              $("#"+fromid+" option:selected").each(function() {    
  478.                  //将源list中的option添加到目标list,当目标list中已有该option时不做任何操作.    
  479.                  $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  480.                  //目标list中已经存在的option并没有移动,仍旧在源list中,将其清空.    
  481.                  if($("#"+fromid+" option[value="+$(this).val()+"]").length >  {    
  482.                      $("#"+fromid).get(    
  483.                      .removeChild($("#"+fromid+" option[value="+$(this).val()+"]").get();    
  484.                  }    
  485.              });    
  486.          }    
  487.      }    
  488.      else if(moveOrAppend.toLowerCase() == "append") {    
  489.          if(isAll == true) {    
  490.              $("#"+fromid+" option").each(function() {    
  491.                  $("<option></option>")    
  492.                  .val($(this).val())    
  493.                  .text($(this).text())    
  494.                  .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  495.              });    
  496.          }    
  497.          else if(isAll == false) {    
  498.              $("#"+fromid+" option:selected").each(function() {    
  499.                  $("<option></option>")    
  500.                  .val($(this).val())    
  501.                  .text($(this).text())    
  502.                  .appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  503.              });    
  504.          }    
  505.      }    
  506.  };   /**   
  507.  功能大体同上("move").   
  508.  不同之处在于当源list中的选中option在目标list中存在时,源list中的option不会删除.   
  509.  isAll参数(true或者false):是否全部移动或添加   
  510.  jQuery.listist = function(fromid,toid,isAll) {    
  511.      if(isAll == true) {    
  512.          $("#"+fromid+" option").each(function() {    
  513.              $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  514.          });    
  515.      }    
  516.      else if(isAll == false) {    
  517.          $("#"+fromid+" option:selected").each(function() {    
  518.              $(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));    
  519.          });    
  520.      }    
  521.  };  
  522.  引自:http://www.cnblogs.com/tangself/archive/2010/04/14/1711684.html 
普通分类: