我有一个我似乎无法克服的困境。场景是我有2个选择列表框#boxdest& #boxdest2。
目的是使用#boxdest中的项目填充#boxdest2,它成功完成。但是,当我发送到结果页面进行处理时,#boxdest将通过而不是#boxdest2来保存项目。有趣的是,#boxdest似乎正在发送正确的数据,实际上是#boxdest2。
如果有人能指出我哪里出错了,我将不胜感激。感谢
<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("sample",$conn);
$result = mysql_query("SELECT * FROM boxes where department = '{$_GET['dept']}' ORDER BY custref ASC");
?>
<select name="boxdest[]" id="boxdest" size="7" multiple="multiple">
<?php
$i=0;
while($row = mysql_fetch_array($result)) {
?>
<option value="<?php echo $row["custref"];?>"><?php echo $row["custref"];?></option>
<?php
$i++;
}
?>
</select>
<span style="display: inline-block; width: 70px; height: 82px; padding-left: 10px; padding-right: 10px; vertical-align: top;margin-top:35px;">
<input type="button" id="submit2" name="submit2" value=">" />
<input type="button" id="submit3" name="submit3" value="<" />
</span>
<select name="boxdest2[]" id="boxdest2" size="7" multiple="multiple"></select>
jquery代码
<script type="text/javascript">
$(document).ready(function () {
// initial list, as fetched from the server
var initialList = $('#boxdest > option')
.map(function () { return this.value; }).get();
/**
* @param {string} source
* @param {string} destination
*/
function exchangeLists(source, destination) {
// find all selected items on the source list
var selected = $(source + ' > option:selected');
// move them to the destination list
$(destination).append(selected.clone());
// remove from the source list
selected.remove();
// sort the destination list
var list = $(destination + ' > option').clone().sort(function (a, b) {
if (initialList.indexOf(a.value) < initialList.indexOf(b.value)) {
return -1;
}
if (initialList.indexOf(a.value) > initialList.indexOf(b.value)) {
return 1;
}
return 0;
});
// replace current destination list with the sorted one
$(destination).empty().append(list);
}
$('#submit2').click(function () {
exchangeLists('#boxdest', '#boxdest2');
});
$('#submit3').click(function () {
exchangeLists('#boxdest2', '#boxdest');
});
});
</script>
答案 0 :(得分:1)
您是否确保物品在盒子之间移动后被选中?当您将项目从左向右移动时,它们在移动后不会被选中,因此它们不会被发布。如果您在提交表单之前重新选择每个框中的项目(例如,通过按住shift并单击它们),它会正确发布它们。