jquery plug-in development notes_jquery
Today I discovered that JQ itself already has a way to store this temporary data:
$("dom").data("mydata","this is data"); Also, when we were developing plug-ins, we It is often necessary to add methods to plug-ins. In fact, just use the method of adding methods inside JS
this.myfn=function(){}
The source code of the previous plug-in that displays part of the text is given below. :
(Similar to CSS text-overflow, but for this plug-in you need to provide a few words to display to accurately control the number of displays)
/**
* demo:
* 1.$("#limittext").limittext();
* 2.$("#limittext").limittext({"limit":1});
* 3.$("#limittext").limittext({"limit":1,"fill":"( 免费最合)","fillid":"aaa"});
* 4.$("#limittext").limittext({"limit":1,"fill":"( 免费最合)","fillid":"aaa"}).limit(10); * 5.$("#limittext").limittext({"limit":1,"fill":"( 免费安全)","fillid":"aaa"}).limit('all');
* @param {Object} opt
* @author Lonely * @link http://liushan.net
*/
jQuery.fn.extend({
limittext:function(opt){
opt=$.extend({
"limit":30,
"fill":"...",
"fillid":null
},opt);
var $this=$(this);
var body=$(this).data('body');
if(body==null){
body=$this.html();
$(this).data('body',body);
}
this.limit=function(limit){
if(body.length<=limit||limit==' all')
var showbody=body;
else{
if(opt.fillid==null)
var showbody=body.substring(0,limit) opt.fill;
else
var showbody=body.substring(0,limit) "" opt.fill "";
}
$(this ).html(showbody);
}
this.limit(opt.limit);
return this;
}
});

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

With the continuous development of the e-commerce market, the methods of selling goods are also constantly updated and iterated. Among them, flash sale activities have become an important part of e-commerce platform marketing, which can attract more users' attention and increase sales. The core of the flash sale activity is an efficient and stable flash sale plug-in. This article will introduce how to use the flash sale plug-in of PHP Developer City. 1. Understand the principle of flash sale plug-in Before developing the flash sale plug-in, we need to understand the principle of flash sale first. When conducting flash sales activities, a time period is usually set, and users can only

With the development of WordPress, more and more users need to customize the functions of WordPress websites. To meet this need, developing your own WordPress plugin is a good option. In this article, we will discuss how to develop custom WordPress plugins using PHP. First, let’s understand the structure of WordPress plugins. In WordPress, plugins are implemented through a folder and must contain a specified file

JavaScript plays a very important role in modern web application development. During the development process, we often encounter situations where we need to develop debugging tools and plug-ins. This article helps readers quickly master related skills by introducing JavaScript debugging tools and plug-in development methods. 1. Development of debugging tools 1. Console The console is one of the most familiar debugging tools for web developers. It provides developers with an interface to record and process debugging information directly in web applications. The console can

Detailed explanation of the underlying development principles of PHP: plug-in development and extension mechanism implementation Introduction: During the development process of PHP applications, we often use various plug-ins and extensions to increase functionality and performance. How are these plug-ins and extensions implemented? This article will analyze in detail the implementation principles of PHP plug-in development and extension mechanisms from the perspective of underlying development, with code examples attached. 1. Plug-in development A plug-in can be understood as an optional, pluggable functional component that can be run and expanded independently in an application. In PHP, the key to plug-in development is to use

In today's Internet era, Java, as a highly versatile programming language, is widely used in the field of software development. As technology continues to advance, developers need to continue to learn and grow in order to keep up with industry developments. As an advanced Java developer, you may not only be satisfied with writing basic applications, but also play a more important role in the project and need to expand application functions and improve application performance and usability. Below we share some experiences and suggestions to help you better complete these tasks. First, understand the business needs

How to add backup and restore function to WordPress plug-in When using WordPress to develop plug-ins, the backup and restore function is a very important function. It can help us easily save and restore data when there is a problem with the plug-in or the website needs to be migrated. This article will explain how to add backup and restore functionality to a WordPress plugin and provide code examples. Create a database table First, we need to create a database table to store the backup data. Open phpMyAdmin or other number

Introduction to the development and debugging of Vue statistical chart plug-in: In modern web development, statistical charts are very common components. They can be used to visualize data, making it easier to understand and analyze. As a popular front-end framework, Vue provides many powerful tools and libraries, including plug-ins for developing and debugging statistical charts. This article will introduce how to use Vue to develop and debug a simple statistical chart plug-in, and provide some code examples. Preparation First, we need a Vue project. Can use Vue

With the popularity and development of content management systems (CMS), extension plug-ins have become an important development requirement. As a popular programming language, PHP can be used to develop various extension plug-ins. This article will introduce how to use PHP to develop extension plug-ins in CMS. Types of Plug-ins First of all, understanding the types of plug-ins is very important for development. There are three common types of plug-ins: templates, modules and plug-ins. Template plug-ins are mainly used to modify the appearance of the CMS, such as changing colors, fonts, layout, etc. Module plug-ins are used to increase the functionality of CMS.
