未显示单击时更改复选框状态

Change checkbox status on click is not being displayed

本文关键字:复选框 状态 显示 单击      更新时间:2023-09-26

复选框状态值存储在localStorage中。'updateStorage'在localStorage中将这些键值对设置为'null'。

只有在页面重新加载后才能看到效果。如何实现在调用函数后直接显示复选框状态的更改,例如toggle

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);

我需要一个过渡吗??

目前我是这样解决的:

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)来选择相同效果的盒子。- ?

我添加了一个带有pseudo:checked的过滤器,只选择选中的框。