<head>
<title></title>
<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js"
type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var checkbox = $('#boxlawreg').find(':checkbox'), checkboxCookieName = 'checkbox-state';
checkbox.each(function () {
$(this).attr('checked', $.cookie(checkboxCookieName + '|' + $(this).attr('name')));
});
checkbox.click(function () {
$.cookie(checkboxCookieName + '|' + $(this).attr('name'), $(this).prop('checked'));
});
});
</script>
</head>
<body>
<div id="boxlawreg">
<input type="checkbox" name="option1" value="1" />1<br />
<input type="checkbox" name="option2" value="2" />2<br />
<input type="checkbox" name="option3" value="3" />3<br />
<input type="checkbox" name="option4" value="4" />4<br />
</div>
</body>fakat bu kodda şöyle bir sıkıntım var. Tıkladığında checkboxa eğer check olmuşsa cookie oluşturuyor. Buraya kadar herşey guzel. Ama checkbox uncheck yapsanız bile gene eskı aldığı cookie yi silmiyor. Bunu checkbox uncheck olduğunda eski aldığın cookie yi sil komutunu nasıl ekleriz acaba. Bir türlü bunu yapmayı başaramadım. Yardımlarınız bekliyorum.
checkbox boşsa cookie silsin
3
●559
- 07-09-2012, 15:57:00Eposta Aktivasyonu GerekmekteMerhaba arkadaşlar. Sitemde bir form hazırladım ve şu kodu kullanıyorum.
- 07-09-2012, 21:31:15Eposta Aktivasyonu GerekmekteArkadaşlar burada adam başarmış ama ben uyarlamayı beceremedim. Yardım ederseniz sevinirim...
http://jsfiddle.net/tovic/z59DP/5/
Arkadaşlar şöyle birşey daha buldum sadece bunda ihtiyacım olan şey div için değilde id si olan tr ler içinde çalışması lütfen yardım edin.
function getStorage(key_prefix) { // this function will return us an object with a "set" and "get" method // using either localStorage if available, or defaulting to document.cookie if (window.localStorage) { // use localStorage: return { set: function(id, data) { localStorage.setItem(key_prefix+id, data); }, get: function(id) { return localStorage.getItem(key_prefix+id); } }; } else { // use document.cookie: return { set: function(id, data) { document.cookie = key_prefix+id+'='+encodeURIComponent(data); }, get: function(id, data) { var cookies = document.cookie, parsed = {}; cookies.replace(/([^=]+)=([^;]*);?\s*/g, function(whole, key, value) { parsed[key] = unescape(value); }); return parsed[key_prefix+id]; } }; } } jQuery(function($) { // a key must is used for the cookie/storage var storedData = getStorage('com_mysite_checkboxes_'); $('div.check input:checkbox').bind('change',function(){ $('#'+this.id+'txt').toggle($(this).is(':checked')); // save the data on change storedData.set(this.id, $(this).is(':checked')?'checked':'not'); }).each(function() { // on load, set the value to what we read from storage: var val = storedData.get(this.id); if (val == 'checked') $(this).attr('checked', 'checked'); if (val == 'not') $(this).removeAttr('checked'); if (val) $(this).trigger('change'); }); });