Home > Backend Development > PHP Tutorial > javascript - 为每个收藏按键添加事件时,为什么“已收藏“总不能变回”收藏“?

javascript - 为每个收藏按键添加事件时,为什么“已收藏“总不能变回”收藏“?

WBOY
Release: 2016-06-06 20:28:51
Original
1160 people have browsed it

<code>//为每个收藏添加一个事件
var colength=$(".col").length;
for(var i=0;i<colength alert if></colength></code>
Copy after login
Copy after login

回复内容:

<code>//为每个收藏添加一个事件
var colength=$(".col").length;
for(var i=0;i<colength alert if></colength></code>
Copy after login
Copy after login

代码贯通了哦

<code>if($(this).text().length==3){
   $(this).css("background","white");
   $(this).text("收藏");
}
//长度编程2
if($(this).text().length==2){
       $(this).css("background","yellow");
   $(this).text("已收藏");
}
</code>
Copy after login

==修改下===

<code>if($(this).text().length==3){
   $(this).css("background","white");
   $(this).text("收藏");
}else if($(this).text().length==2){
       $(this).css("background","yellow");
   $(this).text("已收藏");
}</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template