2
我有一個多選框,允許我選擇多個數值,然後在點擊箭頭時將它們添加到第二個選擇框。現在這部分工作正常,我可以選擇多個值。但是,當我將第二個選擇框的值傳遞給變量時,變量只顯示列表中最後一項的值,而不是全部。多選框僅顯示最後選定的數值
JavaScript代碼
<script type="text/javascript">
$().ready(function() {
$('#add').click(function() {
return !$('#select1 option:selected').remove().appendTo('#select2');
});
$('#remove').click(function() {
return !$('#select2 option:selected').remove().appendTo('#select1');
});
});
</script>
HTML代碼
<form action="insert_email_visitor_list1.php" method="get" name="form1" target="_self" id="form1">
<select multiple id="select1" class="mulitiselect" name="select1">
<option value="1">Date/Time</option>
<option value="2">Company</option>
<option value="3">Location</option>
<option value="4">Nof Pages/Visit</option>
<option value="5">Traffic Source</option>
<option value="6">Search Term</option>
<option value="7">Report</option>
<option value="8">Classification</option>
<option value="9">Owner</option>
<option value="10">Phone</option>
<option value="11">Town</option>
<option value="12">City</option>
<option value="12">Country</option>
<option value="12">Hostname</option>
</select>
<a href="#" id="add"><img src="images/add-arrow.png" alt="" /></a>
selected Columns
<a href="#" id="remove"><img src="images/remove-arrow.png" alt="" /></a>
<select multiple id="select2" name="select2" class="mulitiselect"></select>
<div class="bottom-img"><img src="images/popup-bottomimg.png" alt="" /></div>
<button>
<img src="images/info-icon.png" alt="" />
</button>
<input type="submit" name="send" id="send" value="Submit" />
</form>
PHP代碼
$select2 = $_GET['select2'];
echo "$select2";
基本上我剛過了一些建議,以如果我這個做正確的方法是什麼?
感謝
重複的:http://stackoverflow.com/questions/1227684/how-to -ite-through-multiple-select-options-with-jquery? – Garytje