我错了什么?通过这种方式,我得到的只是firefox浏览器。我没有得到它的chrome,safari和opera。 的 HTML
<a href="javascript:" class="red-btn">red</a>
<a href="javascript:" class="green-btn">green</a>
<!-- Result -->
<div class="red" >Testing Text1</div>
<div class="red" >Testing Text2</div>
CSS
.red {
color: red;
}
.green {
color: green;
}
Jquery的
jQuery(document).ready(function(){
//check if cookie has been set
var cookieColor = $.cookie("selected_class");
if (cookieColor) {
//remove default "red" class and add cookie class
$(".red").removeClass("red").addClass(cookieColor);
}
jQuery(document).on('click',".red-btn",function (){
alert("red color");
//store the value
$.cookie("selected_class", "red");
jQuery(".green").removeClass("green").addClass("red");
});
jQuery(document).on('click',".green-btn",function (){
alert("green color");
//store the value
$.cookie("selected_class", "green");
jQuery(".red").removeClass("red").addClass("green");
});
});