Jquery拖拽并簡(jiǎn)單保存的實(shí)現(xiàn)代碼
更新時(shí)間:2010年11月28日 17:04:02 作者:
今閑著無聊 順便看了下jquery ui的拖拽插件,實(shí)現(xiàn)拖拽的方法很簡(jiǎn)單,看到效果后興奮小下...
但是如何保存順序呢,想到了cookie,但是用如何用cookie保存順序呢,直接保存html代碼下次讀取覆蓋可以,但是總感覺內(nèi)容多的話 保存的東西比較多,后用ui插件獲取id保存id在讀取實(shí)現(xiàn)了順序的保存,廢話不多說..直接看代碼...
<!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 runat="server">
<title></title>
<style type="text/css">
div
{
border: 1px solid red;
}
#myList
{
padding-top: 20px;
width: 500px;
background: #EEE;
list-style-type: none;
}
#myList li
{
height: 30px;
cursor: pointer;
margin: 20px;
border: 1px solid blue;
}
#myList a
{
text-decoration: none;
color: #0077B0;
}
#myList a:hover
{
text-decoration: underline;
}
#myList .qlink
{
font-size: 12px;
color: #666;
margin-left: 10px;
}
</style>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="ui.core.js" type="text/javascript"></script>
<script src="ui.sortable.js" type="text/javascript"></script>
<script src="cookie.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#myList").sortable({ delay: 1, containment: "div", connectWith: ".otherlist", stop: function() {
//alert($("#myList").sortable("serialize"));
//alert($("#myList").sortable("toArray"));
$.cookie("myCookie", $("#myList").sortable('toArray'), { expires: 7 })
}
});
$(".qlink").click(function() {
alert(this.className);
});
if ($.cookie("myCookie")) {
var ids = $.cookie("myCookie").split(",");
for (var i = 0; i < ids.length; i++) {
$("#" + ids[i]).appendTo("#myList");
}
}
});
</script>
</head>
<body>
<div>
<ul id="myList">
<li id="myList_mood"><a href="#">心情</a> </li>
<li id="myList_photo"><a href="#">相冊(cè)</a> <a href="#" class="qlink">上傳</a> </li>
<li id="myList_blog"><a href="#">日志</a> <a href="#" class="qlink">發(fā)表</a> </li>
<li id="myList_vote"><a href="#">投票</a> </li>
<li id="myList_shate"><a href="#">分享</a> </li>
<li id="myList_group"><a href="#">群組</a> </li>
</ul>
</div>
</body>
</html>
呵呵.. 這下看到了效果,不足方面望高手賜教....
復(fù)制代碼 代碼如下:
<!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 runat="server">
<title></title>
<style type="text/css">
div
{
border: 1px solid red;
}
#myList
{
padding-top: 20px;
width: 500px;
background: #EEE;
list-style-type: none;
}
#myList li
{
height: 30px;
cursor: pointer;
margin: 20px;
border: 1px solid blue;
}
#myList a
{
text-decoration: none;
color: #0077B0;
}
#myList a:hover
{
text-decoration: underline;
}
#myList .qlink
{
font-size: 12px;
color: #666;
margin-left: 10px;
}
</style>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="ui.core.js" type="text/javascript"></script>
<script src="ui.sortable.js" type="text/javascript"></script>
<script src="cookie.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#myList").sortable({ delay: 1, containment: "div", connectWith: ".otherlist", stop: function() {
//alert($("#myList").sortable("serialize"));
//alert($("#myList").sortable("toArray"));
$.cookie("myCookie", $("#myList").sortable('toArray'), { expires: 7 })
}
});
$(".qlink").click(function() {
alert(this.className);
});
if ($.cookie("myCookie")) {
var ids = $.cookie("myCookie").split(",");
for (var i = 0; i < ids.length; i++) {
$("#" + ids[i]).appendTo("#myList");
}
}
});
</script>
</head>
<body>
<div>
<ul id="myList">
<li id="myList_mood"><a href="#">心情</a> </li>
<li id="myList_photo"><a href="#">相冊(cè)</a> <a href="#" class="qlink">上傳</a> </li>
<li id="myList_blog"><a href="#">日志</a> <a href="#" class="qlink">發(fā)表</a> </li>
<li id="myList_vote"><a href="#">投票</a> </li>
<li id="myList_shate"><a href="#">分享</a> </li>
<li id="myList_group"><a href="#">群組</a> </li>
</ul>
</div>
</body>
</html>
呵呵.. 這下看到了效果,不足方面望高手賜教....
您可能感興趣的文章:
- JQuery UI的拖拽功能實(shí)現(xiàn)方法小結(jié)
- 簡(jiǎn)單的jquery拖拽排序效果實(shí)現(xiàn)代碼
- jQuery拖拽div實(shí)現(xiàn)思路
- JQuery之拖拽插件實(shí)現(xiàn)代碼
- jquery實(shí)現(xiàn)簡(jiǎn)單的拖拽效果實(shí)例兼容所有主流瀏覽器
- jQuery手機(jī)瀏覽器中拖拽動(dòng)作的艱難性分析
- 基于jquery的一個(gè)拖拽到指定區(qū)域內(nèi)的效果
- jquery 可拖拽的窗體控件實(shí)現(xiàn)代碼
- 基于jquery實(shí)現(xiàn)的鼠標(biāo)拖拽元素復(fù)制并寫入效果
- jQuery拖拽插件gridster使用指南
- jQuery 版元素拖拽原型代碼
- Jquery實(shí)現(xiàn)自定義窗口隨意的拖拽
- jQuery實(shí)現(xiàn)的簡(jiǎn)單拖拽功能示例
相關(guān)文章
使用異步controller與jQuery實(shí)現(xiàn)卷簾式分頁
這篇文章主要介紹了使用異步controller與jQuery實(shí)現(xiàn)卷簾式分頁,使用異步controller與jQuery按需加載內(nèi)容,當(dāng)用戶開始通過網(wǎng)站的內(nèi)容滾動(dòng)時(shí)進(jìn)一步加載內(nèi)容。,需要的朋友可以參考下2019-06-06jQueryPad 實(shí)用的jQuery測(cè)試工具(支持IE,chrome,FF)
這個(gè)jQueryPad也是我無意中在網(wǎng)上看頁面的時(shí)候看到的,下載下來試用了下,感覺很好,這個(gè)軟件是使用WPF開發(fā)的(不過不開源,需要安裝.NET Framework 3.5),整體界面很簡(jiǎn)潔。2010-05-05jQuery實(shí)現(xiàn)菜單欄導(dǎo)航效果
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)簡(jiǎn)單菜單欄導(dǎo)航效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08自定義類似于jQuery UI Selectable 的Vue指令v-selectable
這篇文章主要介紹了自定義類似于jQuery UI Selectable 的Vue指令v-selectable的相關(guān)資料,需要的朋友可以參考下2017-08-08JQuery里面的幾種選擇器 查找滿足條件的元素$("#控件ID")
JQuery里面的幾種選擇器 查找滿足條件的元素$("#控件ID"),使用jquery的朋友可以參考下。2011-08-08jQuery短信驗(yàn)證倒計(jì)時(shí)功能實(shí)現(xiàn)方法詳解
這篇文章主要介紹了jQuery短信驗(yàn)證倒計(jì)時(shí)功能實(shí)現(xiàn)方法,實(shí)例分析了jQuery前臺(tái)倒計(jì)時(shí)功能及ajax交互的相關(guān)技巧,需要的朋友可以參考下2016-05-05