Solution for receiving background return values in select, return values in select background
When performing page form or conditional filtering, how to refresh the select tag value and keep the selected value after refreshing the page. The following two solutions are provided:
Premise: the front-end select label name is type; the backend receives the type value, and returns the type value to the page after the business is completed.
1. assign values to select tags using jquery.
Step 1: add an id for select to facilitate jquery control.
<Select name = "type" id = "type"> <option value = "0"> excellent </option> <option value = "1"> good </option> <option value = "2"> pass </option> </select>
Step 2: Use jquery to receive background type values and assign values to select tags.
<Script type = "text/javascript"> $ (function () {$ ("[name = 'type']"). val ($ {type}) ;}) </script>
Or
<script type="text/javascript"> $(function(){ $("#type").val(${type}); })</script>
Ii. Use jstl to control whether the select option is selected.
<Select name = "type"> <option value = "0" <c: if test = "$ {type = 0}"> selected </c: if >>> excellent </option> <option value = "1" <c: if test = "$ {type = 1}"> selected </c: if> good </option> <option value = "2" <c: if test = "$ {type = 2}"> selected </c: if> pass </option> </select>