我有四个按标题切换的 div(如下所示,我展示了一组)。每个标题链接类与文本字段类之前的类匹配。我希望使用 $this 编写一些干燥器来针对当前类,然后将当前类作为类文本,而不是四次单独编写 javascipt。
important_info_header类将是每个 div 的动态类 。
这种写作不是很好,所以欢迎任何帮助
尝试失败
$(this).click(function() {
$(this+'.text').slideToggle('slow', function() {
//ani complete.
});
});
工作标记
HTML 开始
<h4><a href="javascript:void(0)" class="important_info_header"><%= t("catalog_items.show_lot.important_info_header")%></a></h4>
<div class="important_info_header text">
<p><%= t("catalog_items.show_lot.important_info") %></p>
</div><!-- /text -->
<h4><a href="javascript:void(0)" class="important_info_header"><%= t("catalog_items.show_lot.important_info_header")%></a></h4>
<div class="important_info_header text">
<p><%= t("catalog_items.show_lot.important_info") %></p>
</div><!-- /text -->
<h4><a href="javascript:void(0)" class="rules"><%= t("catalog_items.show_lot.important_info_header")%></a></h4>
<div class="rules text">
<p><%= t("catalog_items.show_lot.important_info") %></p>
</div><!-- /text -->
<h4><a href="javascript:void(0)" class="shipping"><%= t("catalog_items.show_lot.important_info_header")%></a></h4>
<div class="shipping text">
<p><%= t("catalog_items.show_lot.important_info") %></p>
</div><!-- /text -->
HTML 结束
$('.important_info_header').click(function() {
$('.important_info_header.text').slideToggle('slow', function() {
//ani complete.
});
});