elemanlarının dizin konumunu almak
FULL WORKING DEMO & SOURCE
2012 GÜNCELLEME bu okumayı deneyin:
: jquery için
COOKIE eklentisi
JQUERY:
$(function() {
//coockie name
var LI_POSITION = 'li_position';
$('ul#sortable').sortable({
//observe the update event...
update: function(event, ui) {
//create the array that hold the positions...
var order = [];
//loop trought each li...
$('#sortable li').each(function(e) {
//add each li position to the array...
// the +1 is for make it start from 1 instead of 0
order.push($(this).attr('id') + '=' + ($(this).index() + 1));
});
// join the array as single variable...
var positions = order.join(';')
//use the variable as you need!
alert(positions);
// $.cookie(LI_POSITION , positions , { expires: 10 });
}
});
});
HTML:
<ul id="sortable">
<li id="id_1"> Item 1 </li>
<li id="id_2"> Item 2 </li>
<li id="id_3"> Item 3 </li>
<li id="id_4"> Item 4 </li>
<li id="id_5"> Item 5 </li>
</ul>
PHP:
bu sadece bir örnektir ama fikrim var: Eğer kullanım a isteyebilir veritabanı yerine ve geri almak için AJAX kullanın:
<?php
//check if cookie is set..
if (isset($_COOKIE['li_position'])) {
//explode the cockie by ";"...
$lis = explode(';' , $_COOKIE['li_position']);
// loop for each "id_#=#" ...
foreach ($lis as $key => $val) {
//explode each value found by "="...
$pos = explode('=' , $val);
//format the result into li...
$li .= '<li id="'.$pos[0].'" >'.$pos[1].'</li>';
}
//display it
echo $li;
// use this for delete the cookie!
// setcookie('li_position' , null);
} else {
// no cookie available display default set of lis
echo '
<li id="id_1"> Fuji </li>
<li id="id_2"> Golden </li>
<li id="id_3"> Gala </li>
<li id="id_4"> William </li>
<li id="id_5"> Jordan </li>
';
}
?>
İlginç bir Stack Overflow iş parçacığı getiriyorsunuz. Serileştirme yönteminin gitmem gereken yere gidebileceğini düşünüyorum ama parçaları birleştiremiyorum. – Pieter
Yeni güncelleme! bilmeme izin ver! –
Harika! Bu son bir soru bırakıyor: Sayfayı yeniden yüklediğimde lı'nın doğru sırada görünmesini nasıl sağlayabilirim? Bu çerezi PHP ile alabilir miyim? – Pieter