Select and radio form echo to avoid loading and assigning values using jquery
Note:
Copy codeThe Code is as follows: <Body>
<Form method = "post" action = "">
<! -- If the form uses the reset function, the following code is not recommended -->
<Input type = "radio" name = "visible" value = "1"/> display <br>
<Input type = "radio" name = "visible" value = "0"/> hide <br>
<Select name = "orderBy" id = "orderBy">
<Option value = "0"> 0 </option>
<Option value = "1"> 1 </option>
</Select> <br>
<Input type = "reset">
</Form>
</Body>
</Html>
Not recommended: Use the following js Code Copy codeThe Code is as follows: <script type = "text/javascript">
<! --
$ (Function (){
// The default value of the real data is not displayed during playback.
$ ("Input [type = radio] [name = visible]"). each (function (){
If ($ (this). val () = '$ {teacher. visible }'){
$ (This). attr ("checked", "checked ");
}
});
$ ("# OrderBy option"). each (function (){
If ($ (this). val () = '$ {teacher. orderBy }'){
$ (This). attr ("selected", "selected ");
}
});
});
// -->
</Script>
The best practice is to perform logical judgment on the jsp page. Copy codeThe Code is as follows: <! -- The following code is recommended -->
<Input type = "radio" name = "visible" value = "1" <c: if test = "$ {teacher. visible = 1} "> checked =" checked "</c: if>/> display <br>
<Input type = "radio" name = "visible" value = "0" <c: if test = "$ {teacher. visible = 0} "> checked =" checked "</c: if>/> hide <br>