在JS中獲取到form表單的radiobuttons的選中值其實和普通的radiobutton的方法是同樣的。javascript
經常使用的radiobutton會要求設定radiobutton的name屬性和type屬性,而後根據這兩個屬性進行查找,以下:html
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>
而後在JS中代碼以下:java
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>
form表單中radiobuttons的基本設置以下:ide
1 <form:radiobuttons path="isall" items="${fns:getDictList('allType')}" 2 itemLabel="label" itemValue="value" 3 htmlEscape="false" class="" onclick=""/>
這裏沒有顯式的給出radio的name和type,要去渠道這兩個屬性只須要在網頁上查看源代碼,就能夠獲得它的屬性,而後編寫JS便可:this
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 });
我這裏的操做是根據選中值的狀況來顯示或隱藏一部分頁面,將須要顯示或隱藏的部分的style設置爲display:none便可,如:spa
1 <div id="usermsg" class="control-group" style="display: none"> 2 <label class="control-label">用戶帳號:</label> 3 4 <div 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 </div> 11 </div>