<html>
<head>
<script language="javascript">
$(function(){
//For Moving Up..
$("#button Up").click(function(){
$("#listbox > option:selected").each(function(){
var listItem = $(this);
var listItemPosition = $("#listbox option").index(listItem) + 1;
if (listItemPosition == 1) return false;
listItem.insertBefore(listItem.prev());
});
});
//For Moving Down..
$("#button Down").click(function(){
var itemsCount = $("#listbox option").length;
$($("#listbox option:selected").get().reverse()).each(function() {
var listItem = $(this);
var listItemPosition = $("#listbox option").index(listItem) + 1;
if (listItemPosition == itemsCount) return false;
listItem.insertAfter(listItem.next());
});
});
//For Moving right..
$("#button1").click(function(){
$("#list1 >> option:selected").each(function(){
$(this).remove().appendTo("#list2");
});
});
//For Moving Left..
$("#button2").click(function(){
$("#list2 << option:selected").each(function(){
$(this).remove().appendTo("#list1");
});
});
});
</script>
</head>
<body>
<div>
<h3>List A</h3>
<select id="list1" multiple="multiple" rows=2>
<option value=1>Chennai</option>
<option value=2>Bangalore</option>
<option value=3>Kolkata</option>
<option value=4>Pune</option>
</select>
<br/>
<input id="button1" type="button" value=">>" />
<input id="button Up" type="button" value="Move Up" />
<input id="button Down" type="button" value="Move Down" />
</div>
<div>
<h3>List B</h3>
<select id="list2" multiple="multiple" rows=2>
<option value=1>Jackfruit</option>
<option value=2>Papaya</option>
<option value=3>Water Melon</option>
<option value=4>Banana</option>
</select>
<br/>
<input id="button2" type="button" value="<<" />
</div>
</body>
</html>
需要帮助以将所有功能实现为单独的功能。