我需要在字段集中创建一个字段集,该字段集可以在单击时展开和折叠。
我有些东西可以用,但当我展开“展开1”时,它也是扩展“展开1.A”,而不应该展开"1.A“
“扩展1”和“扩展1.A”都应该能够独立扩展。这里有一些非常粗略的代码来展示我想要做的事情。
<div>
<fieldset class="majorpoints">
<legend class="majorpointslegend">Expand 1 [+]</legend>
<div class="hiders" style="display:none">
<ul>
<li>AAA</li>
</ul>
</div>
<fieldset class="majorpoints">
<legend class="majorpointslegend">Expand 1.A [+]</legend>
<div class="hiders" style="display:none">
<ul>
<li>BBB</li>
</ul>
</div>
</fieldset>
</fieldset>
</div>
<div>
<fieldset class="majorpoints">
<legend class="majorpointslegend">Expand 2 [+]</legend>
<div class="hiders" style="display:none">
<ul>
<li>BBB</li>
</ul>
</div>
</fieldset>
</div>以下是使用Jquery的js。
$('.majorpoints').click(function () {
$(this).find('.hiders').toggle();
var legend = $(this).closest('fieldset').children('legend:first');
var value = legend.text();
if (value.indexOf('[+]') >= 0) value = value.replace('[+]', '') + ' [-]';
else value = value.replace('[-]', '') + ' [+]';
legend.html(value);
});我可以调用外部JQuery / JS,但不允许调用外部"CSS“文件。
这是Visual在调试XSL时的限制,超出了问题的范围。
在别人告诉我最好使用JQuery手机之前,先把它放出来,因为它需要外部CSS。
下面是我迄今为止所做工作的一个例子。
编辑
我只是意识到,只要我单击字段集中的任何文本,它就会展开/折叠,但我不想那样做。它只应在单击图例时展开/折叠。
发布于 2014-12-07 22:43:36
尝试将您的JS更改为:
// click event on the legend rather than the fieldset
$('.majorpointslegend').click(function () {
// find the next hider to the legend
$(this).next('.hiders').toggle();
var legend = $(this).closest('fieldset').children('legend:first');
var value = legend.text();
if (value.indexOf('[+]') >= 0) value = value.replace('[+]', '') + ' [-]';
else value = value.replace('[-]', '') + ' [+]';
legend.html(value);
});https://stackoverflow.com/questions/27348332
复制相似问题