在多个选择字段的输入字段中显示值

时间:2015-11-20 12:01:28

标签: javascript jquery html html5

<select name="place_have" class="form-control" multiple>
    <option value="locker">locker</option>
    <option value="storage">storage</option>
    <option value="bathroom">bathroom</option>
    <option value="food">food</option>
    <option value="parking">parking</option>
    <option value="play ground">play ground</option>
    <option value="smoking room">smoking room</option>
</select>

上面选择的值应显示在下面的另一个输入文本字段中。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

使用 jQuery

$("select[name='place_have']").change(function(){
  var value = $(this).val();
  $("input#optionOutput").val(value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="place_have" class="form-control" multiple>
  <option value="locker">locker</option>
  <option value="storage">storage</option>
  <option value="bathroom">bathroom</option>
  <option value="food">food</option>
  <option value="parking">parking</option>
  <option value="play ground">play ground</option>
  <option value="smoking room">smoking room</option>
</select>
<input type="text" id="optionOutput">