我有一个需要动态生成字段的表单,并且这些字段具有调用它们的各种 jquery 函数。基本上,我使用 slideUp 和 slideDown 来根据用户选择的内容显示不同的选项。考虑以下代码
<div class="test">
<div class="red" style="width:100px;height:100px;background-color:red; margin-bottom:10px;"></div>
<div class="green" style="width:100px;height:100px;background-color:green;margin-bottom:10px;"></div>
</div>
<div class="test">
<div class="red" style="width:100px;height:100px;background-color:red;margin-bottom:10px;"></div>
<div class="green" style="width:100px;height:100px;background-color:green;margin-bottom:10px;"></div>
</div>
和jQuery
$('.green').hide();
$('.red').click(function(){
$('.green').show();
});
基本上我只想显示红色之后的绿色框。虽然这个例子很简单,我可以复制我的代码并给第二个项目一个不同的 id,但我的真实形式要复杂得多,所以我想做的是找到一种在每个“测试”div 中按类名定位项目的方法.