问题描述
复选框状态值存储在localStorage中。 'updateStorage'在localStorage中将这些键值对设置为'null'。
仅在页面重新加载后才能看到效果。 调用函数后,如何实现复选框状态的更改以直接显示(例如在切换中)?
d3.select("#update").on("click",updateStorage);
function updateStorage(){
var updatethis = d3.selectAll(".box").each(function(){
var use_it = this.id;
localStorage.setItem(use_it,null);
d3.select(this).property('checked', null); //does not change display directly
});
};
添加此行无济于事
d3.select(this).property('checked', null);
我需要过渡吗?
1楼
现在,我像这样解决它:
d3.select("#update").on("click",updateStorage);
function updateStorage(){
var updatethis = d3.selectAll(".box").filter(":checked").each(function(){
var use_it = this.id;
console.log("updatethisid :" + use_it);
d3.selectAll('.box').property('checked', false);
localStorage.setItem(use_it,null);
});
};
我不确定为什么不能选择带有d3.select(this)的框来达到相同的效果。 -?
我添加了一个带有伪:checked的过滤器,以仅选择复选框。