0
当我点击复选框时,应该启用它,直到我点击复选框,即使应用程序关闭或我在另一个html Page.Once复选框被再次单击时,它应该被禁用。我应该如何启用使用jquery或javascript的复选框?
当我点击复选框时,应该启用它,直到我点击复选框,即使应用程序关闭或我在另一个html Page.Once复选框被再次单击时,它应该被禁用。我应该如何启用使用jquery或javascript的复选框?
另一种选择是HTML 5本地存储。我相信这是在IE 8+和所有其他主流浏览器中支持的。这里是你会怎么做一个例子:
//Runs once the DOM is ready
$(function() {
//Store the check box element in a variable
var checkbox = $("#elementID");
//The change event gets triggered every time the check box element is clicked
checkbox.change(function() {
//Set the checkbox value in local storage
localStorage.setItem("checkboxValue", checkbox.prop("checked"));
});
var checkValue = localStorage.getItem("checkboxValue");
//Since localStorage returns a string, you must catch it
//and then check or uncheck the box
if(checkValue === "true") {
//Check the box
checkbox.prop("checked", true)
}
else {
//Uncheck the box
checkbox.prop("checked", false)
}
});
请记住,这只适用于jQuery版本> 1.6。如果您使用的是jQuery <1.6版本,请将“prop”方法替换为“attr” – 2012-03-01 18:24:44
你的意思是你想存储页面之间的复选框状态?你可以使用phonegap的存储API将它写入某些东西,然后加载该值并在下次加载该页面时更新复选框? – Rup 2012-03-01 13:24:36
为什么不设置启用/禁用的cookie? – Bakudan 2012-03-01 13:31:06