Javascript/Jquery:基于单选/选项框选择显示隐藏的div
考虑到最后一个线程: 我如何适应使其同时适用于收音机盒和复选框 这是我的密码:Javascript/Jquery:基于单选/选项框选择显示隐藏的div,javascript,jquery,checkbox,radio-button,Javascript,Jquery,Checkbox,Radio Button,考虑到最后一个线程: 我如何适应使其同时适用于收音机盒和复选框 这是我的密码: $(document).ready(function() { /* To add more boxes to hide/show, add the name of the field to the array, set the box class to that name + Hide */ // storing the c
$(document).ready(function() {
/* To add more boxes to hide/show, add the name of the field to the array,
set the box class to that name + Hide */
// storing the class names of the HTML elements we want to mess with
var hiddenClassArray = [
"appliedWorkedYes",
"workStudyYes",
"workHistoryYes",
"workWeekEndsYes",
"cprYes",
"aedYes",
"aidYes",
"lifegaurd",
"wsiYes",
"gaurdYes",
"lifegaurdChk",
"fitnessChk",
"fitPTCYes",
"fitGrpYes",
"outdoorAdvChk",
"challengeChk",
"injuryCareChk",
"athTrainYes",
"athTrainYesHide"
];
// looping over each array element, hiding them using jQuery
for(var i = 0; i < hiddenClassArray.length; i++){
// jQuery to append a display none.
$("."+hiddenClassArray[i]+"Hide").css("display","none");
}
// ************ RADIO & CHECK BOXES ************
// Show using toggle
$.each(hiddenClassArray, function(index, radio) {
// first is it a Check box?
if($("."+radio).is(':checkbox')) {
// toggle it then
$("." + radio).click(function() {
$("." + radio + "Hide").toggle('fast');
});
}
// if it's a radio box
else if ($("."+radio).is(':radio')) {
// user clicked something
$("." + radio).change(function() {
// if it's yes, show
if($("."+radio).val()==="Yes") {
$("."+radio).show("slow");
}
// hide it.
else{
$("."+radio).hide();
}
}
}
}); // end .each
}); // Ending the $(Doc) Ready
$(文档).ready(函数(){
/*要添加更多要隐藏/显示的框,请将字段的名称添加到数组中,
将box类设置为该名称+隐藏*/
//存储要处理的HTML元素的类名
变量hiddenClassArray=[
“应用工作染料”,
“工作研究”,
“工作历史是”,
“工作周是”,
“是的”,
“是的”,
“是的”,
“生命之歌”,
“wsiYes”,
“戈尔德耶斯”,
“生命之歌”,
“fitnessChk”,
“Fitpcyes”,
“fitGrpYes”,
“户外广告”,
“挑战者”,
“伤害车”,
“是的”,
“阿瑟里耶施德”
];
//在每个数组元素上循环,使用jQuery隐藏它们
对于(var i=0;i
乍一看,您只需检查复选框是否已选中。然后使用该复选框显示或隐藏您的项目
$("." + radio).click(function() {
$("." + radio + "Hide").toggle('fast', $(this).is(":checked"));
});