为什么这段代码不起作用:
$("#page1").live('pageinit', function() {
if (localStorage.fullscreen == "true") {
$("#page1").attr("data-fullscreen", "true"); // doesn't work
alert("should be fullscreen now"); // this works
}
if (localStorage.theme) {
$("header").attr("data-theme", localStorage.theme); // this doesn't work
alert("should be theme " + localStorage.theme); // this works
}
});
According to the docs,它应该有效。我也试过了
$("header").data("theme", localStorage.theme);
但这也不起作用。
答案 0 :(得分:0)
尝试使用jquery data api:
$("#page1").data("fullscreen", "true");
$("header").data("theme", localStorage.theme);
答案 1 :(得分:0)
您需要使用其他活动,因为在pageinit
页面已经增强并忽略了您的其他属性。
http://jquerymobile.com/test/docs/api/events.html
请尝试使用pagecreate
或pagebeforecreate
。
这应该有效:
$("#page1").live('pagecreate', function() {
if (localStorage.fullscreen == "true") {
$("#page1").attr("data-fullscreen", "true"); // doesn't work
alert("should be fullscreen now"); // this works
}
if (localStorage.theme) {
$("header").attr("data-theme", localStorage.theme); // this doesn't work
alert("should be theme " + localStorage.theme); // this works
}
});