JQuery中DOM事件合成用法实例分析

2020-05-22 17:06:22易采站长站整理


$(function(){
$("#panel h5.head").toggle(function(){
$(this).next().toggle();
},function(){
$(this).next().toggle();
})
})

为了能有更好的用户体验,现在需要在用户单击“标题”链接后,不仅显示“内容”,而且高亮显示“标题”。代码为:


$(function(){
$("#panel h5.head").toggle(function(){
$(this).addClass("highlight");
$(this).next().show();
},function(){
$(this).removeClass("highlight");
$(this).next().hide();
});
})

运行代码后,如果“内容”是显示的,“标题”则会高亮显示:如果“内容”是隐藏的,则不会高亮显示“新闻标题”。

希望本文所述对大家的jQuery程序设计有所帮助。