Using the s:radio tag of Struts2 and adding change events with jquery_jquery
WBOY
Release: 2016-05-16 17:37:59
Original
1289 people have browsed it
Summary of the use of the s:radio tag in struts2
Problems encountered: When using this tag, the default selected item is set, but after the submitted data is returned, the radio button cannot be displayed before The selected item is still the default option The following conclusions are drawn through testing:
WithFor example When using the s:radio tag, if you want the tag to select one item by default, There are two methods 1. Implement it through js code
Set the radio selection through the value attribute When the default option of the box is selected, the status of the radio button is to select the default item whenever the page is refreshed Therefore, if you want the data to be submitted to the background, the radio button will still be the previously selected item, and the value cannot be passed The attribute sets its default item, which should be set through the first method In addition, the background can correctly obtain the value of the radio button, regardless of the value setting
Use jquery for Struts2 tag adding change event
When using the tag of Struts2, I want to add a change event to it, because this tag is automatically generated for the page A radio group cannot be controlled as usual. I have searched a lot online but haven’t found anything satisfactory. If you set an id for this as before, a number will be automatically added to the generated radio group, such as:
This can be achieved with the help of jquery. It is very simple. Add an attribute cssClass to this ="filetype" will add a css class to each radio, as you can see above, then the next code is as follows:
$(function(){ $(".filetype").change(function(){ var val = $(" input[name='file']:checked").val();//Get the value of the selected radio if(val=='1'){ alert("Yes"); }else{ alert(“No”); } }); });
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn