如何在输入(type=";Radio "and checked ="checked &qu
How to add active class on the span next of the input (type=" radio "and checked ="checked ")?
我想添加一个活动类到span旁边的输入无线电有状态检查,我们有15相同的div在页面
给出的代码是:
<div id="age_restric1" class="singleselect">
<label for="age_restriction" class="required">Age Restriction <span class="required">*</span></label>
<div class="ms-parent">
<button class="ms-choice" type="button" style="width: 58px;"><span class=""> 18+</span>
<div class=""></div>
</button>
<div class="ms-drop top" style="width: 58px; display: none;">
<ul style="max-height: 250px;">
<li>
<label>
<input type="radio" value="" name="selectItem">
<span>None</span></label>
</li>
<li>
<label>
<input type="radio" checked="checked" value="18+" name="selectItem">
<span>18+</span></label>
</li>
<li>
<label>
<input type="radio" value="19+" name="selectItem">
<span>19+</span></label>
</li>
</ul>
</div>
</div>
</div>
<div class="singleselect">
<label class="required" for="appropriate_atti">Appropriate Attire <span class="required">*</span></label>
<div class="ms-parent">
<button class="ms-choice" type="button" style="width: 130px;"><span class=""> Casual</span>
<div></div>
</button>
<div class="ms-drop bottom" style="width: 130px;">
<ul style="max-height: 250px;">
<li>
<label>
<input type="radio" value="" name="selectItem">
<span>--Select Attire--</span></label>
</li>
<li>
<label>
<input type="radio" value="339" name="selectItem">
<span>Business Casual</span></label>
</li>
<li>
<label>
<input type="radio" checked="checked" value="338" name="selectItem">
<span>Casual</span></label>
</li>
</ul>
</div>
</div>
</div>
Javascript: setTimeout(customdrop, 200);
function customdrop(){
$(".singleselect :checked").each(function(){
$(this).next('span').addClass('active');
});
}
可以使用
$('.singleselect input[type="radio"]:checked+span')
访问选中无线电旁边的<span>
。
$("{
if($('input').is(':checked')) {
$(this).closest('li').find('span').addClass('active');
}
});
try this
jQuery("input[name=selectItem]").each(function(){
if(jQuery(this).is(':checked')){
jQuery(this).next('span').addClass('active');
}
})
$(";{
if($('input[type=radio]').is(':checked')) {
$(this).closest('li').find('span').addClass('active');
}
});
使用属性选择器 jquery
$(".singleselect [type=radio]:checked").each(function () {
$(this).next('span').addClass('active');
});
function customdrop() {
$(".active").removeClass('active');
$(this).next('span').addClass('active');
}
$(".singleselect [type=radio]").on("change", customdrop);
<<h2>更新演示/h2> 相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 检测电话窃听,即:<a href="电话:xxx">在UIWebview上
- 使用“+="操作人员
- //而不是在src=“”上使用http://"属性
- "未捕获的语法错误:意外的标记}"
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- "实例范围”;TypeScript类的getter/setter
- Javascript复选框函数:;缺少:在属性id之后"
- "“;变量未引用正确的对象
- "日期“;AJAX请求返回的类型值未定义
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- "工具提示"jQuery插件坏了
- "锻造;React中的表达式
- 图像可以从源<img src=""/>.TEXT可以在没有javascript的情况下从外部
- 如何提取“;href"最近列表项中的属性值
- CKEditor如何允许href="javascript:void(0)"在小部件中
- 插入“;img src"在javascript中