0
<head>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<script language="javascript" type="text/javascript">
$(function() {
$("#MoveRight,#MoveLeft").click(function(event) {
var id = $(event.target).attr("id");
var selectFrom = id == "MoveRight" ? "#SelectLeft" : "#SelectRight";
var moveTo = id == "MoveRight" ? "#SelectRight" : "#SelectLeft";
var selectedItems = $(selectFrom + " :selected").toArray();
$(moveTo).append(selectedItems);
alert('abcd');
});
});
</script>
</head>
<body>
<form method="get">
<select id="SelectLeft" multiple="multiple">
<option value="1">Uruguay</option>
<option value="2">United States</option>
<option value="3">Germany</option>
<option value="4">Argentina</option>
</select>
<input id="MoveRight" type="button" value=" >> " />
<input id="MoveLeft" type="button" value=" << " />
<select id="SelectRight" multiple="multiple">
<option value="5">South Korea</option>
<option value="6">Ghana</option>
<option value="7">England</option>
<option value="8">Mexico</option>
</select>
</form>
</body>
上面的代碼可以在選項標記中使用硬編碼值正常工作。但是當我嘗試&從數據庫中獲取值並填充列表時,代碼不起作用。使用jQuery在列表框之間移動項目
<tr>
<td>
<select id="SelectLeft" multiple="multiple">
<c:forEach var="left" items="${leftList}">
<option value="${left}">${left}</option>
</c:forEach>
</select>
</td>
<td>
<input id="MoveRight" type="button" value=" >> " />
<input id="MoveLeft" type="button" value=" << " />
</td>
<td>
<select id="SelectRight" multiple="multiple">
<c:forEach var="right" items="${rightList}">
<option value="${right.rightRole.roleId}">
${right.rightRole.roleName}</option>
</c:forEach>
</select>
</td>
</tr>
值從數據庫列表中檢索,但兩個列表框之間移動項目的功能不能正常工作。
非常感謝Reigel ..銷售代表你:) – Sandeep 2010-06-24 09:37:28