selectize.js不发送所有选定的选项,只发送最后一个选项

时间:2014-09-05 07:06:01

标签: php selectize.js

我很少选择下拉列表与selectize.js很好地配合使用。在表单帖子上,它似乎只发送选择的最后一个选项。例如,如果用户在var_dump($ _ POST)后面的表格中选择:A,B,C;只有C出现。其他选择的情况也是如此。

我浏览了文档并在网上搜索但无法纠正,我确信这些内容非常简单,但直到我知道,我才不知道:(

非常感谢任何帮助!谢谢!

1 个答案:

答案 0 :(得分:8)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="http://brianreavis.github.io/selectize.js/js/selectize.js"></script> 



<?php
 if(isset($_POST["save"])){
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';



 }

?>

<form action="" method="post">
<label>Select Class(s)</label>
<select multiple id="classname" name="classname[]" required class="form-control">
    <option value="1">NUR</option>
    <option value="2">KG</option>
    <option value="3">PREP</option>
    <option value="4">I</option>
    <option value="5">II</option>
</select>
<label>Subjects</label>
<select multiple id="subjects" name="subjects[]" required class="form-control">
    <option value="1">English</option>
    <option value="2">EVS</option>
    <option value="3">Maths</option>
    <option value="4">Science</option>
    <option value="5">Social</option>
</select>
<label>Examinations</label>
<select multiple="multiple" id="exams" name="exams[]" required="true" class="form-control">
    <option value="1">Formative Assessment I</option>
    <option value="2">Formative Assessment II</option>
    <option value="3">Formative Assessment III</option>
    <option value="4">Formative Assessment IV</option>
    <option value="5">Annual</option>
</select>

<input type="submit" name="save" value="save" />
</form>

<script>
     $(document).ready(function () {
     $('#exams').selectize({
         hideSelected: 'true'
     });

     $('#subjects').selectize({
         hideSelected: 'true'
     });

     $('#classname').selectize({
         hideSelected: 'true'
     });
 });

</script>