我正在使用此页面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>
答案 0 :(得分:0)
值存储在Keeporder数组中,因此您需要在PHP代码中获取keeporder数组
$hidden=array();
$hidden = $_POST['keeporder']; //get the values from the keeporder
print_r($hidden);