jQuery implementation of click follow and cancel function examples
This Internet slang comes from the "like" function of online communities. The number of likes you send and receive, your preferences for giving likes, etc., can to some extent reflect who you are and what state you are in. Behind the likes, you are reflected. Corresponding to this is the cancel function. It happened that the blogger recently worked on an APP, and one of the sections needed to implement the like and cancel functions. After thinking about it, he decided to use JQuery code to implement it.
First we need to introduce the JQuery plug-in
Secondly, we need to define a p and give it some styles
Then there is the JS code, as shown below
$(document).ready(function(){ var onOff=true; var p=$(".p"); p.click(function(){ if (p.onOff) { p.val("关注我"); p.css({"background":'#ccc'}); p.onOff = false; } else { p.css({"background":'red'}); p.val("已关注"); p.onOff = true; } }); });
The effect is as follows
Visible JS code It is easy to use. Similarly, you can also achieve the image switching effect as shown below
The implementation code is as follows
html:
<p class="p"></p>
css: Pay attention to the image path
.p{ background-image: url(img/guanzhu.png); width: 100px;height: 40px;background-size:80px;background-repeat: no-repeat; }
JS code
$(document).ready(function(){ var onOff=true; var p=$(".p"); p.click(function(){ if (p.onOff) { p.css({"background-image":'url(img/guanzhu.png)'}); p.onOff = false; } else { p.css({"background-image":'url(img/yiguanzhu.png)'}); p.onOff = true; } }); });
Related recommendations:
Summary of relevant precautions about verification
Explanation of the following function
10 recommended articles about following events
The above is the detailed content of jQuery implementation of click follow and cancel function examples. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When placing orders using Meituan, users can choose to cancel the orders they do not want. Many users do not know how to cancel Meituan orders. Users can click on the My page to enter the order to be received, select the order that needs to be canceled and click Cancel. How to cancel an order with Meituan 1. First, click on Meituan My Page to enter the order to be received. 2. Then click to enter the order that needs to be canceled. 3. Click Cancel Order. 4. Click OK to cancel the order. 5. Finally, select the reason for cancellation according to your personal situation and click Submit.

1. The ear symbol is the voice receiver mode. First, we open WeChat. 2. Click me in the lower right corner. 3. Click Settings. 4. Find the chat and click to enter. 5. Uncheck Use earpiece to play voice.

When many users experience Mango TV, a video software, they choose to become members in order to enjoy more film and television resources and more comprehensive services. In the process of using Mango TV membership services, some users will choose to turn on the automatic renewal function to enjoy the discounts to ensure that they will not miss any exciting content. However, when users no longer need membership services or want to change the payment method, canceling the automatic renewal function is a very important thing to protect the safety of property. How to cancel the automatic renewal service of Mango TV? Users who want to know Come and follow this article to learn more! How to cancel the automatic renewal of membership on Mango TV? 1. First enter [My] in the Mango TV mobile APP, and then select [VIP Membership]. 2. Then find [Tube

1. Click the [iTunesStore and AppStore] option in the phone settings. 2. Click [View AppleID], and then enter the login password. 3. Enter the [Account Settings] interface and click [Payment Information]. 4. Check the payment method as [None] and click [Finish]. After completion, return to the WeChat interface. At this time, you will receive the [Successful Cancellation Notification] message, and WeChat will no longer automatically deduct fees.

Alipay is a very practical life service platform. This software is very powerful. It provides users with functions such as life payment, travel, medical insurance, etc., bringing convenience to everyone's life. The Alipay platform has many functions waiting for everyone to unlock, so how do you cancel face-swiping payment on Alipay? Detailed tutorial on canceling face-swiping payment on Alipay: 1. First open Alipay 2. Click on My in the lower right corner 3. Click on Settings in the upper right corner 4. Click on payment settings 5. Click on biometric payment 6. Find the mobile phone to scan the face to pay 7. Uncheck the software features 1. Support various scene relationships, group chat and group payment are more convenient; 2. Establish family accounts for children and parents; 3. Free long-distance inter-bank transfers and credit card repayments

Why don’t others see my attention on Weibo? We only need to classify the blogger into the group "Follow quietly" so that others will not see that we are following him. 1. Open Weibo on your mobile phone and click [Follow] on the homepage. 2. Click [Follow quietly] in "My Group". How to check visitor records on Weibo? 1. The visitor recording function tested on Weibo is currently only visible to SVIP and VVIP, and is only open to some users. 2. Users can find the visitor record entrance in [More Functions] under the personal center, where they can view the number of visitors, the visitors, and the people who visit more frequently. 3. This function is only open to SVIP and VVIP users, and is temporarily unavailable to ordinary users and ordinary member users. 4. In short, Weibo test visitors

As a well-known short video e-commerce platform in China, Doudian provides merchants with convenient sales channels and a broad user base. On Doudian, merchants need to deliver goods in time to meet users' shopping needs, but sometimes due to various reasons, merchants may need to cancel shipments within 48 hours. So, how does Doudian cancel shipments within 48 hours? 1. How to cancel delivery within 48 hours on Doudian? Merchants can cancel shipments in Doudian's backend management system. After logging in to the backend management system, merchants can easily find the orders that need to be canceled and select the corresponding orders for operation. By clicking the Cancel Shipping button, the system will pop up a prompt to confirm the cancellation. After the merchant confirms, the order can be successfully canceled. This operation applies to orders shipped within 48 hours

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <
