【发布时间】:2014-04-03 21:39:38
【问题描述】:
饼干:
$(document).ready(function(){
//hide all divs just for the purpose of this example,
//you should have the divs hidden with your css
//$('.picture.1').hide();
//check if the cookie is already setted
if ($.cookie("currentDiv")===undefined){
$.cookie("currentDiv",1);
} else{ //else..well
//get and increment value, let's suppose we have just 8 divs
var numValue = parseInt($.cookie("currentDiv"));
numValue = numValue + 1;
if (numValue>8){
//restart to 1
$.cookie("currentDiv",1);
}
else{ //no issues, assign the incremented value
$.cookie("currentDiv",numValue.toString());
}
//show the div
$('.picture.'+$.cookie("currentDiv")).show();
$('.current'+$.addClass(.cookie("currentDiv")); <--
}
});
分区:
<div class="current"></div>
然后我设置一个从 1 到 8 的样式,所以如果它是“当前 1”,它会显示数字 1 cookie 的工作原理:如果尚未设置 cookie,它会设置一个 cookie,并将其称为“currentDiv”,并给它一个从 1 到 8 的数字,如果访问过的 cookie 大于 8,则刷新 cookie。 但是如何使用这个 cookie/jquery 将该类添加到 div 它需要添加一个类,因为它会阻止浏览器数据,而且我有一个数字从 0 到 9 的 svg
谢谢,清酒
【问题讨论】:
-
如果对你有帮助,请看我的回答
-
css类名不能以数字开头(见w3.org/TR/CSS21/grammar.html#scanner)。
标签: javascript jquery html css cookies