久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

基于條件的jQuery可拖動(dòng)還??原

jQuery draggable revert based on condition(基于條件的jQuery可拖動(dòng)還??原)
本文介紹了基于條件的jQuery可拖動(dòng)還??原的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我遇到了一個(gè)與 jQuery 可拖放相關(guān)的問題.這是描述我想做的事情.

首先:我有兩個(gè) div.一個(gè)是

,另一個(gè)是 <div id="container">.container"有 10 個(gè) <li> 可以拖放到selected"中.這是代碼:

<div id="selected"><ul class="可排序列表"></ul></div><div id="容器"><ul class="可排序列表"><li>1</li><li>2</li><li>....</li><li>9</li><li>10</li></ul></div>

第二:我想允許任何 5 個(gè) <li>s 從容器"到選定"div.如果有人試圖添加第 6 個(gè) <li>,那么它一定不允許用戶添加它.即第 6 個(gè) <li> 必須使用 jQuery 可拖動(dòng)選項(xiàng) revert.

$("#container li").draggable({ revert: true });這是 javascript 代碼.

$(document).ready(function(){變量總計(jì) = 0;$("#selected").droppable({下降:函數(shù)(){總計(jì) = $("#selected li").length;//警報(bào)(總計(jì));如果(總數(shù)> = 5){$("#container li").draggable({ revert: true });} 別的 {//下面的代碼不工作$("#container li").draggable({ revert: false });//這讓整個(gè)功能變得很奇怪.我可以拖動(dòng)所有的<li>任何地方}}});});

這工作正常.

第三:但是當(dāng)我將一個(gè) <li> 從selected"拖到container"時(shí),selected"div 將只有 4 個(gè) <li>s.所以在這種情況下,稍后用戶應(yīng)該能夠?qū)⒘硪粋€(gè) <li> 從容器" div 添加到選定" div 中.但不幸的是,它不起作用.由于 if (total >= 5 ) 條件,我嘗試拖放到已選擇"中的所有 <li> 都將被還原.

誰能幫我解決這個(gè)問題,使用 draggable revert 選項(xiàng)?請(qǐng)...

解決方案

你可以使用accept 選項(xiàng),它需要一個(gè)函數(shù)來更容易地做到這一點(diǎn),像這樣:

$("#selected ul").droppable({接受:函數(shù)(){return $("#selected li").length <5個(gè);}});

你可以在這里測(cè)試一下.當(dāng)您將元素拖出時(shí),.length 會(huì)下降,它會(huì)再次接受元素...沒有理由變得更復(fù)雜:)

I am having an issue related jQuery draggable and droppable. Here is description something what I want to do.

First: I have two divs. One is <div id="selected"> and another is <div id="container">. "container" has 10 <li> which are draggable and droppable into "selected". Here is code:

<div id="selected">
    <ul class="sortable-list">
    </ul>
</div>


<div id="container">
    <ul class="sortable-list">
             <li>1</li>
             <li>2</li>
             <li>....</li>
             <li>9</li>
             <li>10</li>
    </ul>
</div>

Second: I want to allow any 5 <li>s from "container" to "selected" div. If someone tries to add 6th <li>, then it must not allow user to it. That is the 6th <li> that is going to be inserted into "selected" must be reverted using jQuery draggable option revert.

i.e. $("#container li").draggable({ revert: true }); Here is javascript code for that.

$(document).ready(function(){

    var total = 0;
    $("#selected").droppable({
        drop: function() {
                total = $("#selected li").length;
                //alert(total);
                if (total >= 5) {
                    $("#container li").draggable({ revert: true });
                } else {
                            // below code is not working
                    $("#container li").draggable({ revert: false }); // this is making whole feature weird. I can drag all the <li> anywhere
                }
            }
    });
});

This is working fine.

Third: But when I drag an <li> from "selected" to "container", the "selected" div will have only 4 <li>s. So in this situation, later on user should be able to add another <li> into "selected" div from "container" div. But unfortunately it is not working. All the <li>s I try to drag and drop into "selected" are being reverted due to if (total >= 5 ) condition.

Can anyone help me to solve this out using draggable revert option? Please...

解決方案

You can use the accept option which takes a function to do this much easier, like this:

$("#selected ul").droppable({
    accept: function() {
        return $("#selected li").length < 5;
    }
});

You can test it out here. When you drag elements out, the .length goes down and it'll accept elements again...no reason to get any more complicated :)

這篇關(guān)于基于條件的jQuery可拖動(dòng)還??原的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創(chuàng)建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設(shè)置值/標(biāo)簽的問題)
how to unit-test private methods in jquery plugins?(如何對(duì) jquery 插件中的私有方法進(jìn)行單元測(cè)試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動(dòng)網(wǎng)站配置偏移量/對(duì)齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當(dāng)文本框獲得焦點(diǎn)時(shí)選擇所有內(nèi)容)
主站蜘蛛池模板: 国产午夜精品视频 | 天天综合影院 | 欧美精品久久久久 | 青草福利视频 | 91狠狠综合| 成人免费精品 | 亚洲成色www.777999 | 欧美日韩一区二区三区四区 | av网站观看 | 日日夜夜狠狠 | 亚洲国产天堂 | 欧美黑粗大 | 精品小视频 | 国产一级片网站 | 国产精品伦理一区 | 日本免费在线观看 | 91青青草 | 欧美精品区| 中文字幕二区 | 亚洲久久久 | 久热精品视频 | 中文字幕在线免费看 | 国产探花视频在线观看 | 天天躁日日躁bbbbb | 青青草久久 | 亚洲精品在线视频观看 | 欧美一区二区三区四区五区 | 亚洲精品国产一区 | 精品欧美一区二区三区久久久 | 久久免费精品 | 久久久久久久免费视频 | 欧美日韩在线不卡 | 青青草伊人网 | 精品一区二区三区免费 | 在线视频亚洲 | 欧美午夜视频 | 超碰在线91| 男人的天堂亚洲 | 国产一区二区三区视频在线 | 日韩一级免费 | 好色婷婷 |