Select and radio form echo functions avoid using jquery to load values

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.