如何将下拉列表的选定值用于 Apache Velocity 中另一个标签的文本

How to use selected value of dropdown into text of another label in Apache Velocity

我在 Apache Velocity 中有一个下拉列表,我需要使用下拉列表的选定值作为标签的文本:

<select name="fruits" id="fruits">
  <option value="apple">Apple</option>
  <option value="watermelon">Watermelon</option>
</select>

这是我的标签:

<label id="selectedValue""> //I need value of selected value here </label>

如何在 apache velocity 中使用下拉列表中的选定值到另一个标签的文本中?

您可以使用jQuery:JSFiddle

$(document).ready(function() {
    $(function() {
        $('#fruits').on('change', function(){
            var selected_fruits = $(this).find("option:selected").val();

            $("#selectedValue").empty();
            $('#selectedValue').append(selected_fruits);
        });
    });
});