獲取select 所有option &&select 移除和新增 選中的option
阿新 • • 發佈:2018-12-17
//獲取select 所有option 方法 var months= $("#addedmonths").map(function(){ return $(this).val(); }).get().join(", “) ; //select 移除和新增 選中的option KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲addmonths").app…(”#addedmonths").find(“option:selected”).remove()); //記得引入jQuery
<script> function addmon(){ $("#addedmonths").append($("#addmonths").find("option:selected").remove()); //下面這個也可以實現 /* var options = $('#addmonths option:selected'); $("#addedmonths").append(options);*/ } function delmon() { $("#addmonths").append($("#addedmonths").find("option:selected").remove()); } </script>
<table border="1" bordercolor="#6B9EC6"width="90%" class="Table" align="center"> <tbody> <tr> <td align="center"> <b> 選擇新增的月份 </b> </td> <td align="center"> <b> 操作 </b> </td> <td align="center"> <b> 已新增的月份 </b> </td> </tr> <tr> <td align="center" style="width:40%;height:300px"> <select id="addmonths" name="addmonths" multiple="true" style="height:85%;width:50px" > <option value="01"> 1月 </option> <option value="02"> 2月 </option> <option value="03"> 3月 </option> <option value="04"> 4月 </option> <option value="05"> 5月 </option> <option value="06"> 6月 </option> </select> </td> <td align="center"> <a id="addmon" name="addmon" href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:addmon()">>></a> <br> <a id="delmon" name="delmon" href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:delmon()"><<</a> </td> <td align="center" style="width:40%;height:300px"> <select id="addedmonths" name="addedmonths" multiple="true" style="height:85%;width:50px" > </select> </td> </tr> </tbody> </table>