我正在使用此页面http://loudev.com/中的 jQuery MultiSelect - 视觉上一切正常,但我需要按照选择它们的顺序输出数据。
本文在此处发布了一个解决方法jquery multiselect selected data order,但我是一个完全的初学者,需要一些帮助来实施该解决方案。
理想情况下,我想在文本字段中输出所选项目。任何帮助深表感谢。
<html>
<link href="multiselect.css" media="screen" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.multiselect.js"></script>
<script type="text/javascript">
$(function() {
$('#keep-order').multiSelect({ keepOrder: true });
});
</script>
<script>
$(function(){
$('#keep-order').multiSelect({
afterSelect: function(value, text){
var get_val = $("#multiple_value").val();
var hidden_val = (get_val != "") ? get_val+"," : get_val;
$("#multiple_value").val(hidden_val+""+value);
},
afterDeselect: function(value, text){
var get_val = $("#multiple_value").val();
var new_val = get_val.replace(value, "");
$("#multiple_value").val(new_val);
}
});
});
</script>
</head>
<body>
<form method="post">
<select multiple="multiple" id="keep-order" name="keeporder[]">
<option value='elem_1'>elem 1</option>
<option value='elem_2'>elem 2</option>
<option value='elem_3'>elem 3</option>
<option value='elem_4'>elem 4</option>
<option value='elem_5'>elem 5</option>
<option value='elem_6'>elem 6</option>
<option value='elem_7'>elem 7</option>
<option value='elem_8'>elem 8</option>
<option value='elem_9'>elem 9</option>
<option value='elem_10'>elem 10</option>
</select>
<input type="hidden" name="multiple_value" id="multiple_value" />
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_POST['submit'])){
$hidden = $_POST['multiple_value']; //get the values from the hidden field
$hidden_in_array = explode(",", $hidden); //convert the values into array
$filter_array = array_filter($hidden_in_array); //remove empty index
$reset_keys = array_values($filter_array); //reset the array key
var_dump($reset_keys); //the result
}
?>
</body>
</html>