需要达到的功能效果就是当点击radio或checkbox时,显示或隐藏某div,这个功能主要用于表单或后台功能配置项,在优美主题配置中也运用到,这样有利于提升用户体验,选择功能显示对应的功能配置。实现代码如下:1,js代码$(document).ready(function() { //单选触发 &nbs...
需要达到的功能效果就是当点击radio或checkbox时,显示或隐藏某div,这个功能主要用于表单或后台功能配置项,在优美主题配置中也运用到,这样有利于提升用户体验,选择功能显示对应的功能配置。实现代码如下:
1,js代码
$(document).ready(function() { //单选触发 $(".radioItem").change(function() { var $selectedvalue = $("input[name='test1']:checked").val(); if ($selectedvalue == 1) { alert('选项一'); } else { alert('选项二'); } }); //多选触发 $("input[type='checkbox']").click(function() { if ($(this).is(":checked")) { alert('已选中') } else { alert('未选中') } }); });
2,html代码
<p> <input id="radio1" class="radioItem" name="test1" type="radio" value="1" checked="checked"><label for="radio1">选项一</label> <input id="radio2" class="radioItem" name="test1" type="radio" value="2"><label for="radio2">选项二</label> </p> <p> <input id="test2" name="test2" type="checkbox" value=""><label for="test2">多选一</label> <input id="test3" name="test3" type="checkbox" value=""><label for="test3">多选二</label> </p>
演示效果:
此处为隐藏内容,请评论后查看隐藏内容,谢谢!