The method of obtaining the selected value of the radiobuttons of the form form in JS is actually the same as the ordinary radiobutton. Commonly used radiobuttons require setting the name attribute and type attribute of the radiobutton, and then searching based on these two attributes, as follows:
1 <br/>2 <input name="radio" type="radio" checked="checked" value="男"/>男3 <input name="radio" type="radio" value="女"/>女4 <br/><br/><br/>5 <label id="message">哈哈哈哈</label>
Then the code in JS is as follows:
1 <script type="text/javascript"> 2 $(function(){ 3 $("input[name='radio']").click(function() { 4 if($(this).val() == "男") { 5 $("#message").show(); 6 } else{ 7 $("#message").hide(); 8 } 9 }); 10 })11 </script>
In the form form The basic settings of radiobuttons are as follows:
1 <form:radiobuttons path="isall" items="${fns:getDictList('allType')}"2 itemLabel="label" itemValue="value"3 htmlEscape="false" class="" onclick=""/>
The name and type of the radio are not explicitly given here. To access these two attributes of the channel, you only need to view the source code on the web page to get its attributes, and then Just write JS:
1 $(function () { 2 3 $("input[name='isall']").click(function () { 4 if ($(this).val() == "0") { 5 $("#usermsg").hide(); 6 } else { 7 $("#usermsg").show(); 8 } 9 }); 10 });
My operation here is to display or hide part of the page according to the selected value. Set the style of the part that needs to be displayed or hidden to display: none, such as:
1 <p id="usermsg" class="control-group" style="display: none"> 2 <label class="control-label">用户账号:</label> 3 4 <p class="controls"> 5 <input id="user_id" type="text" maxlength="100" name="userId" class="input-medium"/> 6 <shiro:hasPermission name="doctor:doctormsgpush:edit"> 7 <input type="submit" value="查询用户ID" onclick="check()" 8 class="btn btn-primary"/> 9 </shiro:hasPermission>10 </p>11 </p>
Related recommendations:
How to get Jquery Detailed example of radio selected value
JS Get radio selected value example code
The above is the detailed content of JS gets the selected values of radios and buttons in the form. For more information, please follow other related articles on the PHP Chinese website!