Home  >  Article  >  Web Front-end  >  How jQuery modifies the style under li and the src value of img under li_jquery

How jQuery modifies the style under li and the src value of img under li_jquery

WBOY
WBOYOriginal
2016-05-16 16:32:181789browse

How jQuery modifies the style under li and the src value of img under li. The following is the specific implementation code. Friends who need it can take a look

$(".test li").click(function() {
$(".test li a").removeClass("test01");
$(".test li a").addClass("test02");
$("a", this).removeClass("test02");//当前li中的a标签
$("a", this).addClass("test01");
var title_index = $(this).index();//当前li的index
//li中所有的img
var allImg = $(".test li img");
for ( var i = 0; i < allImg.size(); i++) {
if (i % 2 == 0) {
$(allImg[i]).attr("src", "images/b04.gif");//改变img的src
} else {

$(allImg[i]).attr("src", "images/b05.gif");
}
}
//当前li中的img
var imgs = $("img", this);
for ( var i = 0; i < imgs.size(); i++) {
if (i == 0) {
$(imgs[i]).attr("src", "images/b01.gif");
} else {

$(imgs[i]).attr("src", "images/b02.gif");
}

}
if (title_index == 0) {
$("#a).hide();
$("#b").show();
} else {
$("#b").hide();
$("#a").show();
} 
})

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn