Use jquery to add a change event to the <s: radio/> label of Struts2.

Source: Internet
Author: User
When the & lt; s: radio/& gt; tag of Struts2 is used, you want to add a change event to it. Because this tag automatically generates a radio group for the page, it cannot be controlled as usual. I spoke a lot on the Internet and did not find a satisfactory one. If you set an id for this & lt; s: radio/& gt; as before, generate... SyntaxHi

Use Struts2 You want to add a change event to a tag. Because this tag automatically generates a radio group for the page, it cannot be controlled as usual. I spoke a lot on the Internet and did not find a satisfactory one. If you give this Set an id. A number is automatically added to the generated radio group, for example:

 


No

Yes

 


In this case, jquery can be used for implementation, which is very simple. Add cssClass = "filetype" to add a css class for each radio. The following code is shown:

 

 

[Javascript]
$ (Function (){
$ (". Filetype"). change (function (){
Var val = $ ("input [name = 'file']: checked"). val (); // obtain the value of the selected radio
If (val = '1 '){
Alert ("yes ");
} Else {
Alert ("no ");
}
});
});

$ (Function (){
$ (". Filetype"). change (function (){
Var val = $ ("input [name = 'file']: checked"). val (); // obtain the value of the selected radio
If (val = '1 '){
Alert ("yes ");
} Else {
Alert ("no ");
}
});
});

 

 


You can perform corresponding operations each time you select radio.

 

Related Article

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.