【发布时间】:2012-06-19 01:31:12
【问题描述】:
这里是JS Fiddle。我希望内容具有一定的交互性,只需单击内容即可隐藏它。为了允许用户在他/她愿意的情况下将其带回,隐藏部分出现在右侧的<aside> 部分中。我有“标题”(业务方法)工作,因为它必须保留为父 DOM 元素。我一直在努力让孩子们工作。我目前对孩子们的尝试是/是这个(也张贴在小提琴上):
//individual BA elements Toggle Buttons
//Currently on, turning Off
$('.block > .businessapproaches > section > input').on('change', function () {
if (this.checked) {
} else {
var index = $(this).prevAll('section').length;
$('.block > .businessapproaches > section').eq(index).hide();
$('fieldset.businessapproaches > label').eq(index+1).show();
$('fieldset.businessapproaches > input').eq(index+1).prop('checked' , false);
console.log("off")
console.log("left index: " + index);
console.log($('.block > .businessapproaches > section').eq(index));
console.log($('fieldset.businessapproaches > label').eq(index+1));
}
});
//Currently off, turning On
$('fieldset.businessapproaches > input').on('change', function () {
if (this.checked) {
} else {
var index = $(this).prevAll('section').length+1;
$('.block > .businessapproaches > section').eq(index-1).show();
$('.block > .businessapproaches > input').eq(index-1).prop('checked' , false);
$('fieldset.businessapproaches > label').eq(index).hide();
console.log("on")
console.log("right index: " + index);
console.log($('.block > .businessapproaches > section').eq(index-1));
console.log($('fieldset.businessapproaches > label').eq(index));
}
});
很抱歉在同一个堆栈中发布 2 个问题,但它似乎相关,我正在努力快速达到 125 的代表,因此我可以发布多个问题而无需等待规定的时间)
奖励积分:能告诉我为什么“标题”(业务方法)可以通过复选框或文本单击,而子项则不能?我的错误在哪里,因为我最终会用 css 隐藏“框”。
【问题讨论】:
标签: javascript jquery html show-hide