質問する
65220 次
4 に答える
103
var $options = $("#myselect > option").clone();
$('#secondSelectId').append($options);
于 2012-05-28T08:28:47.273 に答える
14
<select multiple="true" class="multiselect1" name="myselecttsms1">
<option value="1" rel="0" title="One">One</option>
<option value="2" rel="1" title="Two">Two</option>
<option value="4" rel="3" title="Four">Four</option>
<option value="5" rel="4" title="Five">Five</option>
<option value="6" rel="5" title="Six">Six</option>
</select>
<select multiple="true" class="multiselect2" name="myselecttsms2" size="6">
</select>
<button class="add">Add</button>
<button class="addAll">Add All</button>
<button class="remove">Remove</button>
<button class="removeAll">Remove All</button>
jQuery:
$('.add').on('click', function() {
var options = $('select.multiselect1 option:selected').sort().clone();
$('select.multiselect2').append(options);
});
$('.addAll').on('click', function() {
var options = $('select.multiselect1 option').sort().clone();
$('select.multiselect2').append(options);
});
$('.remove').on('click', function() {
$('select.multiselect2 option:selected').remove();
});
$('.removeAll').on('click', function() {
$('select.multiselect2').empty();
});
于 2012-05-28T08:41:47.703 に答える