jquery實(shí)現(xiàn)可拖動(dòng)DIV自定義保存到數(shù)據(jù)的實(shí)例
看到一個(gè)不錯(cuò)的jquery插件,可拖動(dòng)DIV,順序可保存到數(shù)據(jù)庫(kù)的一個(gè)實(shí)例:這里就以其中PHP實(shí)例簡(jiǎn)單說明一下:
<?php
//post到后臺(tái)的數(shù)據(jù)
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.dbjr.com.cn/">Homepage</a><br/>
<br/>
<h2>Save list order with ajax:</h2>
<ul id="gallery">
<?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為回調(diào)函數(shù)
$("#gallery").dragsort({ dragSelector: "div", dragEnd: saveOrder, placeHolderTemplate: "<li class='placeHolder'><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 style="clear:both;"></div>
</div>
</body>
</html>
- jQuery實(shí)現(xiàn)的鼠標(biāo)拖動(dòng)浮層功能示例【拖動(dòng)div等任何標(biāo)簽】
- jquery div拖動(dòng)效果示例代碼
- jQuery拖動(dòng)div、移動(dòng)div、彈出層實(shí)現(xiàn)原理及示例
- jQuery實(shí)現(xiàn)單擊彈出Div層窗口效果(可關(guān)閉可拖動(dòng))
- jquery拖動(dòng)改變div大小
- 使用jQuery的easydrag插件實(shí)現(xiàn)可拖動(dòng)的DIV彈出框
- jQuery實(shí)現(xiàn)Div拖動(dòng)+鍵盤控制綜合效果的方法
- jQuery實(shí)現(xiàn)鼠標(biāo)拖動(dòng)div改變位置、大小的實(shí)踐
相關(guān)文章
前端開發(fā)部分總結(jié)[兼容性、DOM操作、跨域等](持續(xù)更新)
在公司做這個(gè)項(xiàng)目已經(jīng)6個(gè)多月了,總結(jié)一些問題,也算是拋磚引玉吧,希望更多的朋友一起分享一些技巧。2010-03-03jQuery實(shí)現(xiàn)左側(cè)導(dǎo)航模塊的顯示與隱藏效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)左側(cè)導(dǎo)航模塊的顯示與隱藏效果,涉及jQuery相應(yīng)鼠標(biāo)事件動(dòng)態(tài)操作頁(yè)面元素樣式的相關(guān)技巧,需要的朋友可以參考下2016-07-07jQuery中元素選擇器(element)簡(jiǎn)單用法示例
這篇文章主要介紹了jQuery中元素選擇器(element)用法,簡(jiǎn)單通俗的說明了jQuery元素選擇器的功能、用法并結(jié)合實(shí)例形式分析了jQuery元素選擇器的相關(guān)使用技巧與注意事項(xiàng),需要的朋友可以參考下2018-05-05基于jquery實(shí)現(xiàn)的仿優(yōu)酷圖片輪播特效代碼
這篇文章主要為大家介紹了基于jquery實(shí)現(xiàn)的仿優(yōu)酷圖片輪播特效代碼,感興趣的小伙伴們可以參考一下2016-01-01jquery實(shí)現(xiàn)全屏滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)全屏滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08jQuery-ui中自動(dòng)完成實(shí)現(xiàn)方法
關(guān)于jQuery-ui-1.8中的自動(dòng)完成控件,其匹配方式是使用正則表達(dá)式進(jìn)行匹配的。2010-06-06ASP.NET jQuery 實(shí)例1(在TextBox里面創(chuàng)建一個(gè)默認(rèn)提示)
通常用戶在搜索內(nèi)容時(shí),在文本框輸入內(nèi)容前,文本框都會(huì)給出默認(rèn)提示,提示用戶輸入正確的內(nèi)容進(jìn)行搜索2012-01-01