Tim*_*ora 96
这里有一个小样本可以帮助您入门:http://jsfiddle.net/eUDRV/3/
此示例将从左到右移动项目(一个或多个),然后再移回.无论在右侧选择了哪个项目,都将更新右侧的文本框.
我们正在使用这些元素:
selectinput type="button"input type="text"陷害者:
divsection采用简单的CSS设计.功能由JavaScript提供.
我正在使用jQuery库让事情变得更容易一些.这也可以使用纯JavaScript完成.
$("#btnLeft").click(function () {
var selectedItem = $("#rightValues option:selected");
$("#leftValues").append(selectedItem);
});
$("#btnRight").click(function () {
var selectedItem = $("#leftValues option:selected");
$("#rightValues").append(selectedItem);
});
$("#rightValues").change(function () {
var selectedItem = $("#rightValues option:selected");
$("#txtRight").val(selectedItem.text());
});Run Code Online (Sandbox Code Playgroud)
SELECT, INPUT[type="text"] {
width: 160px;
box-sizing: border-box;
}
SECTION {
padding: 8px;
background-color: #f0f0f0;
overflow: auto;
}
SECTION > DIV {
float: left;
padding: 4px;
}
SECTION > DIV + DIV {
width: 40px;
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<section class="container">
<div>
<select id="leftValues" size="5" multiple></select>
</div>
<div>
<input type="button" id="btnLeft" value="<<" />
<input type="button" id="btnRight" value=">>" />
</div>
<div>
<select id="rightValues" size="4" multiple>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<div>
<input type="text" id="txtRight" />
</div>
</div>
</section>Run Code Online (Sandbox Code Playgroud)