//为每个收藏添加一个事件
var colength=$(".col").length;
for(var i=0;i<colength;i++){
$(".col").eq(i).click(function(){
alert($(this).text().length);//这地方提示是正常的,
//但当出现3时,并没有执行第一个if,这是为什么呢?
if($(this).text().length==3){
$(this).css("background","white");
$(this).text("收藏");
}
if($(this).text().length==2){
$(this).css("background","yellow");
$(this).text("已收藏");
}
})
}//为每个收藏添加一个事件
var colength=$(".col").length;
for(var i=0;i<colength;i++){
$(".col").eq(i).click(function(){
alert($(this).text().length);//这地方提示是正常的,
//但当出现3时,并没有执行第一个if,这是为什么呢?
if($(this).text().length==3){
$(this).css("background","white");
$(this).text("收藏");
}
if($(this).text().length==2){
$(this).css("background","yellow");
$(this).text("已收藏");
}
})
}
代码贯通了哦
if($(this).text().length==3){
$(this).css("background","white");
$(this).text("收藏");
}
//长度编程2
if($(this).text().length==2){
$(this).css("background","yellow");
$(this).text("已收藏");
}
==修改下===
if($(this).text().length==3){
$(this).css("background","white");
$(this).text("收藏");
}else if($(this).text().length==2){
$(this).css("background","yellow");
$(this).text("已收藏");
}
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号