<!DOCTYPE html>
<html>
<head>
<title>下拉框</title>
<link href="/static/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/static/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/jQuery/jquery-5.1.1.min.js"></script>
<style type="text/css">
.selectc{
float: left;
}
.button1{
float: left;
width: 120px;
height: 200px;
}
button{
width: 120px;
}
</style>
</head>
<body>
<div>
<label>姓名</label>
<input type="text" name="">
<label>爱好</label>
<input type="text" name="">
</div>
<div class="selectc">
<select multiple="true" id="selected1" style="width: 150px;height: 200px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div class="button1">
<button id="add" class="btn btn-default">选中添加到右边</button>
<button id="add_all" class="btn btn-default">全部添加右边</button>
<button id="romve" class="btn btn-default">选中添加到左边</button>
<button id="romve_all" class="btn btn-default">全部添加左边</button>
</div>
<div class="selected">
<select multiple="true" id="selected2" style="width: 150px;height: 200px;"></select>
</div>
<div class="form-group">
</div>
</body>
</html>
<script type="text/javascript">
$(function(){
$("#add").on('click',function(){
$('#selected1 option:selected').appendTo('#selected2');
});
$("#add_all").on('click',function(){
$('#selected1 option').appendTo('#selected2');
});
$("#romve").on('click',function(){
$('#selected2 option:selected').appendTo('#selected1');
});
$("#romve_all").on('click',function(){
$('#selected2 option').appendTo('#selected1');
});
$('#selected1 option').on('dblclick',function(){
$(this).appendTo('#selected2');
});
});
</script>
jQuery实现下拉框应用选择
于 2020-05-06 21:17:40 首次发布