我有一个选择框,将用于一些后端排序。下面,我通过将要排序的项放在中间,然后将当前选定的项(在此方案中)放在后面,给出新顺序的可视化表示。
我需要一种方法来获取前一个选项的文本(因此该选项直接位于当前选定选项之前),这样我就可以填充前一个项的文本。我该怎么做?
<p>Select an item in the following list that you want this item to go <i>before</i>.</p>
<select name="order-list" id="order-list" class="form-control">
{array_to_select($list)}
</select>
<p class="m-t-md">Presentation order after changes:</p>
<ul class="list-group">
<li class="list-group-item" id="sortable-item-before">Before Item</li>
<li class="list-group-item" id="sortable-item-current">{$current_item}</li>
<li class="list-group-item" id="sortable-item-after">After Item</li>
</ul>
<script>
$(document).ready(function () {
var before = $('#sortable-item-before');
var after = $('#sortable-item-after');
$('#order-list').on('change', function (e) {
e.preventDefault();
after.html($(this).find('option:selected').text());
});
});
</script>
示例列表选项:
<option value="68">Some option</option>
**不能假定值是连续的。