(多选)排列选项取决于用户选择

时间:2016-02-03 05:34:40

标签: javascript jquery codeigniter

有没有人知道怎么做 JQuery 并按顺序获取所选选项取决于用户选择?

    <select class="form-control" name="cols[]" multiple="multiple" id="cols[]" required="required">
                        <option value="latest_upd">Latest Update</option>
                        <option value="status">Status</option>
                        <option value="spin">SPIN</option>
                        <option value="file_location">File location</option>
                        <option value="upl_webgis">uploaded to webgis</option>
                        <option value="rem_upl">Remarks on upload</option>
    </select>

1 个答案:

答案 0 :(得分:0)

试试这个:使用PHP和Jquery

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>   
</head>
<body>
<?php
echo "<pre>",print_r($_POST,1),"</pre>";
?>
    <form action="" method="post">
    <select class="form-control" name="cols[]" multiple="multiple" id="cols[]" required="required">
      <option value="latest_upd">Latest Update</option>
      <option value="status">Status</option>
      <option value="spin">SPIN</option>
      <option value="file_location">File location</option>
      <option value="upl_webgis">uploaded to webgis</option>
      <option value="rem_upl">Remarks on upload</option>
    </select>
    <input type="submit">
    </form>
    <script type="text/javascript">
    $(document).on('submit',function() {
        var result = '';
      $('select[name="cols[]"]').find('option:selected').each(function() {
         result = $('select[name="cols[]"]').val();
      });
      alert(result);
    });
    </script>
</body>
</html>