JQUERY操作单选框(radio)
在表单填写中常常碰到使用Jquery操作radio的问题。这里记录一个自己曾遇到的问题。
在aspx文件中使用一个RadioButtonList控件显示两个radio标签。表示一对选中状态:
1 <asp:RadioButtonList runat="server" ID="rblShow" class="show" 2 3 RepeatDirection="Horizontal"> 4 5 <asp:ListItem Text="是" value="1" /> 6 7 <asp:ListItem Text="否" value="0"/> 8 9 </asp:RadioButtonList> 10 11 <p class="isShow" style="width: 500px"> 12 测试文字 13 </p>
然后在脚本js中添加Jquery引用后。
1 <script type="text/javascript"> 2 $(function () { 3 $(":radio").click(function () { 4 if ($(this).val() == "1") { 5 $(".isShow").fadeIn(); 6 } else { 7 $(".isShow").fadeOut(); 8 } 9 }) 10 })
$(":radio").click(function () 添加对radio的js事件,然后判断value后,对后面的测试文字进行淡入淡出操作。
OK,操作完成。如此便可以自由的操作页面上的任何元素了。