国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jquery實現可拖動DIV自定義保存到數據的實例

2024-05-06 15:55:36
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了jquery實現可拖動DIV自定義保存到數據,有需要的朋友可以參考一下

看到一個不錯的jquery插件,可拖動DIV,順序可保存到數據庫的一個實例:這里就以其中PHP實例簡單說明一下:

復制代碼 代碼如下:


<?php 
//post到后臺的數據 
    if ($_POST) { 
        $ids = $_POST["ids"]; 
        for ($idx = 0; $idx < count($ids); $idx+=1) { 
            $id = $ids[$idx]; 
            $ordinal = $idx; 
            //... 
        } 
        return; 
    } 
?> 

復制代碼 代碼如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <style type="text/css"> 
        body { font-family:Arial; font-size:12pt; padding:20px; width: 800px; margin:20px auto; border:solid 1px black; } 
        h1 { font-size:16pt; } 
        h2 { font-size:13pt; } 
        ul { width:350px; list-style-type: none; margin:0px; padding:0px; } 
        li { float:left; padding:5px; width:100px; height:100px; } 
        li div { width:90px; height:50px; border:solid 1px black; background-color:#E0E0E0; text-align:center; padding-top:40px; } 
        .placeHolder div { background-color:white!important; border:dashed 1px gray !important; } 
    </style> 
</head> 
<body> 
    <div> 
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 

        <h1>jQuery List DragSort PHP Example</h1> 

        <a href="http://www.survivalescaperooms.com/">Homepage</a><br/> 
        <br/> 

        <h2>Save list order with ajax:</h2> 

        <ul> 
            <?php 
                $list = array("blue", "orange", "brown", "red", "yellow", "green", "black", "white", "purple"); 
                for ($idx = 0; $idx < count($list); $idx+=1) { 
                    echo "<li data-itemid='" . $idx . "'>"; 
                    echo "<div>" . $list[$idx] . "</div>"; 
                    echo "</li>"; 
                } 
            ?> 
        </ul> 

        <script type="text/javascript" src="jquery.dragsort-0.5.1.min.js"></script> 
        <script type="text/javascript"> 
//saveOrder為回調函數 
            $("#gallery").dragsort({ dragSelector: "div", dragEnd: saveOrder, placeHolderTemplate: "<li><div></div></li>" }); 

            function saveOrder() { 
                var data = $("#gallery li").map(function() { return $(this).data("itemid"); }).get(); 
            //通過ajax模擬post的方式,post格式形式為:[0, 1, 2, 5, 4, 3, 8, 6, 7]  
                $.post("example.php", { "ids[]": data }); 
            }; 
        </script> 

        <div></div> 
    </div> 
</body> 
</html> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 洮南市| 永济市| 喀喇沁旗| 张家川| 铜鼓县| 定边县| 平江县| 安泽县| 肇州县| 沾益县| 塘沽区| 泊头市| 哈尔滨市| 岳池县| 建宁县| 泰宁县| 疏勒县| 遵义市| 西和县| 榆林市| 咸宁市| 曲沃县| 绩溪县| 兴文县| 高邑县| 长治县| 兴化市| 汝南县| 尼木县| 山东省| 乐陵市| 柘城县| 鹰潭市| 望奎县| 乌拉特后旗| 凤城市| 隆回县| 富平县| 汉沽区| 买车| 牡丹江市|