jQuery dragging elements and reordering elements_jquery
The example in this article describes the implementation method of dragging elements and reordering elements with jQuery. It is shared with everyone for your reference. The specific implementation content is as follows
Rendering:
The specific content is as follows:
From the picture above you can see the function we want to implement today. When the user drags an image, he or she can change the existing sorting of the image and update the order in the table. For example, users can drag the layout of our website at will, as Google iGoogle has already implemented. This greatly improves the user experience.
Below, we will implement this function step by step.
<span id="show"> <div> <input id="check" type="checkbox" /> </div> <div> <input type="hidden" id="orderlist" /> <ul id="list"> <asp:Repeater ID="rptOrder" runat="server"> <ItemTemplate> <li id="<%#Eval("ID") %>" title="<%#Eval("OrderID") %>"> <jQuery dragging elements and reordering elements_jquery alt="jQuery dragging elements and reordering elements_jquery" src="<%#Eval("Link") %>" /> </li> </ItemTemplate> </asp:Repeater> </ul> </div>
There is a radio button. When the user selects it, the sorting of the data in the database will be changed when the image is dragged. The hidden field saves the original order of pictures. ul displays the picture list.
To make it easier to see, I added a little style:
var show = jQuery("#show"); //输出提示 var orderlist = jQuery("#orderlist"); //原顺序 var check = jQuery("#check"); //是否更新到数据库
First save the commonly used selectors so that calling them later becomes simpler. Everyone will definitely have no problem with this one. ^_^
//保存原来的排列顺序 var order = []; list.children("li").each(function() { order.push(this.title); //原排列顺序保存在title,得到后更改title jQuery(this).attr("title", "你可以拖动进行排序"); }); orderlist.val(order.join(','));
Save the original sort order to the hidden field. The push() method of the array is used here, which is to add the title (original arrangement order) in each li of ul to the array. Finally, the join() method is used to obtain the original arrangement order and return a string. The sort order format is now 1,2,3.
//ajax更新 var Update = function(itemid, itemorder) { jQuery.ajax({ type: "post", url: "update.aspx", //id:新的排列对应的ID,order:原排列顺序 data: { id: itemid, order: orderlist.val() }, beforeSend: function() { show.html("正在更新"); }, success: function() { show.html("更新成功"); } }); };
Next, separate the ajax update block separately. This way the program becomes cleaner and there is nothing new in this area.
//调用ajax更新方法 var Submit = function(update) { var order = []; list.children("li").each(function() { order.push(this.id); }); var itemid = order.join(','); //如果单选框选中,则更新表中排列顺序 if (update) { Update(itemid); } else { show.html(""); } };
Similar to getting the sort order, the ID is composed into a string and passed to the Update() method. The parameter update in the function is whether the checkbox is selected.
//执行排列操作 list.sortable({ opacity: 0.7, update: function() { Submit(check.attr("checked")); } });
Finally, perform the sorting operation. The background part is the update of the current ID corresponding to the original arrangement order. I believe everyone is familiar with it.
It can be seen that if no database operation is performed, the plug-in only needs to call sorttable to complete the dragging of elements.
The above is the implementation method of jQuery dragging elements and reordering elements. I hope it will be helpful to everyone's learning.

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

AI Hentai Generator
Generate AI Hentai for free.

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



In our work, we often use wps software. There are many ways to process data in wps software, and the functions are also very powerful. We often use functions to find averages, summaries, etc. It can be said that as long as The methods that can be used for statistical data have been prepared for everyone in the WPS software library. Below we will introduce the steps of how to sort the scores in WPS. After reading this, you can learn from the experience. 1. First open the table that needs to be ranked. As shown below. 2. Then enter the formula =rank(B2, B2: B5, 0), and be sure to enter 0. As shown below. 3. After entering the formula, press the F4 key on the computer keyboard. This step is to change the relative reference into an absolute reference.

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

In this article, we will show you how to reorder multiple columns in PowerQuery by dragging and dropping. Often, when importing data from various sources, columns may not be in the desired order. Reordering columns not only allows you to arrange them in a logical order that suits your analysis or reporting needs, it also improves the readability of your data and speeds up tasks such as filtering, sorting, and performing calculations. How to rearrange multiple columns in Excel? There are many ways to rearrange columns in Excel. You can simply select the column header and drag it to the desired location. However, this approach can become cumbersome when dealing with large tables with many columns. To rearrange columns more efficiently, you can use the enhanced query editor. Enhancing the query

WPS is a very complete office software, including text editing, data tables, PPT presentations, PDF formats, flow charts and other functions. Among them, the ones we use most are text, tables, and demonstrations, and they are also the ones we are most familiar with. In our study work, we sometimes use WPS tables to make some data statistics. For example, the school will count the scores of each student. If we have to manually sort the scores of so many students, it will be really a headache. In fact, we don’t have to worry, because our WPS table has a sorting function to solve this problem for us. Next, let’s learn how to sort WPS together. Method steps: Step 1: First we need to open the WPS table that needs to be sorted

Sorting methods in excel: 1. Single column sorting; 2. Multiple column sorting; 3. Custom sorting. Detailed introduction: 1. Single-column sorting is the most common sorting method. It sorts according to a selected column; 2. Multi-column sorting refers to sorting data in multiple columns, usually sorting according to a certain column first. On the basis of, sort by another column; 3. Custom sorting, allowing users to define the sort order according to their own needs.

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: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
