Multiple Select 元素選取 - Jquery
<script type="text/javascript">
function AddItem() {
var optionStr = "";
$("#ExamineItem :selected").each(function () {
//alert($(this).text());
//判斷是否有重複選取的物件
var SelectedExamineItem = $("#SelectedExamineItem");
var ExamineItem = $(this);
var check = true;
$(SelectedExamineItem).find("option").each(function () {
if ($(ExamineItem).text() == $(this).text()) {
check = false;
}
});
if (check) {
optionStr += "<option value='" + $(this).text() + "'>" + $(this).text() + "</option>";
}
});
if (optionStr != "") {
$("#SelectedExamineItem").append(optionStr);
}
}
function CanelItem() {
$("#<%= SelectedExamineItem.ClientID %> :selected").each(function () {
$(this).remove();
});
}
</script>
<body>
<select id="ExamineItem" name="ExamineItem" style=" width:200px; height:100px" multiple>
</select>
<input type="button" value=">" onclick="AddItem()" />
<input type="button" value="<" onclick="CanelItem()" />
<select id="SelectedExamineItem" name="SelectedExamineItem" style=" width:200px; height:100px" multiple>
</select>
</body>
標籤: Jquery