有没有人知道怎么做 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>
答案 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>