At that time, I copied a few sentences from the official website of jquery to get started, but later I found that it was not very useful and it was quite slow. Sweat~~~ I didn’t figure out how to save the sorted results until this morning. It just so happened that the company was going to build such a function, so I learned it all over again.
First of all, I found similar code on jquery’s official demo (http://jqueryui.com/demos/). What I want is called portlets (http://jqueryui.com/demos/sortable/portlets.html). Just like the igoogle homepage. It seems to be very simple. After adding all the js to be quoted, then a few lines of code are done.
html code omitted... Please view the demo for details
After writing these, you can try dragging. Do you feel a sense of accomplishment? Not bad, young man, there is a future. sortable has many parameters, go to the official website for details! Let's just talk about what connectWith:'.column' means here. It means that any portlet with class column can drag the portlet of one column to another column. Just try it and you will know. Of course, the focus today is not how to drag it, but that refreshing after dragging still preserves the current order.
You have encountered a little difficulty, but you have to do it, otherwise no girl will marry you in the future! ^_^ So I started to Google Baidu. Some people say that you can get an ID array using the serialize method of sortable, but unfortunately, I didn't get it. If you do it, please tell me; some people say that you can also get the ID array using the toArray method. I did get it this time. But something very nasty happened.
$('.column').sortable('toArray');
In this way, you can only get the ID array whose first class is column. Use each()? I tried , but not work; Maybe you can do it, please tell me! So I can only turn to other methods. Maybe you will say, isn't this simple? Wouldn't it be OK to just save the layout of the entire web page? Haha, I also think so! Through the iedeveloper debugging tool, I found that after dragging, they found changes. It was not the style that changed, but the order of the divs. If I save the entire content, it seems to work, but the amount is a bit large and not suitable for dynamic content. What should I do, so I thought, wouldn’t it be O if I just save their IDs in order? So I gave each of them an ID.
Everything is difficult at the beginning. After you have this idea, have you opened the toilet? I'll go take a rest first. Thank you for opening the door. I'll be right back!
Let’s follow this idea step by step. The first is to get all the columns.
$.each($(".column"), function(m) {}
Then find the portlet under each column;
$.each($(".column"), function(m) {
$.each($(this).children(".portlet"), function(d) {
}
Then save them in your own way
function saveLayout(){
var list = "";
$.each($(".column"), function(m) {
list = $(this).attr( 'id') ":";
$.each($(this).children(".portlet"), function(d) {
list = $(this).attr('id') " @";
})
list = "|";
})
$.cookie("list", list)}
Another method is also used here One component jquery.cookie
Change the starting
$(".column").sortable({
connectWith: '.column',
stop: saveLayout
});
stop refers to dragging Events triggered after the end.
Finally, it is read into the container in order. I won’t say much here, I can only understand it, not explain it in words:
var list = $.cookie("list"); //Get the list in the cookie Value
//alert(list)
var arrColumn = list.split('|');
$.each(arrColumn, function(m, n) {
var elemId = n.split (':')[0]; //Container ID
var arrRow = n.split(':')[1] ? n.split(':')[1].split('@') : ""; //Single sequence ID
$.each(arrRow, function(m, n) {
if (n) {//Exclude null values
$("#" elemId).append( $("#sb" n).attr('id', n))//Add the sequence into the container
}
});
})
Okay, that’s it for today. It took me an hour to type and typeset, and the company gave me 16 RMB per hour. So BYE!
If you have any questions, please don’t ask me, I’m very busy. Go to QQ group 5678537 to find other people to discuss!
Demo codehttp://demo.jb51.net/js/Sortable/Sortable.htm

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
