简体   繁体   English

如何覆盖复选框选中的属性

[英]How to override the checkbox checked property

In the JavaScript page I have three checkboxes - 1, 2 and 3 of which the 1st box is always checked (I used checked="checked") on page load.在 JavaScript 页面中,我有三个复选框 - 1、2 和 3,在页面加载时始终选中第一个框(我使用了 checked="checked")。 If the user uncheck the 1st box, check 2nd and 3rd box and save.如果用户取消选中第一个框,请选中第二个和第三个框并保存。 Now on page load the 2nd and 3rd box should only be checked.现在在页面加载时,只应选中第二个和第三个框。 How can I achieve this?我怎样才能做到这一点? I am new to JavaScript.我是 JavaScript 的新手。 Thanks谢谢

What happens on save?保存时会发生什么? When a page load happens you need to fetch the "saved" values from somewhere and check the boxes in javascript page load event.当页面加载发生时,您需要从某处获取“已保存”值并选中 javascript 页面加载事件中的框。 I think you could use just the browsers sessionstorage for this since it's just temporary form data - I assume:我认为您可以只使用浏览器会话存储,因为它只是临时表单数据 - 我假设:

https://www.w3schools.com/html/html5_webstorage.asp . https://www.w3schools.com/html/html5_webstorage.asp https://www.w3schools.com/jsref/prop_checkbox_checked.asp https://www.w3schools.com/jsref/prop_checkbox_checked.asp

So on pageload check if there are any "form data" in storage and check the boxes that were saved in memory.因此,在页面加载时,检查存储中是否有任何“表单数据”并选中保存在 memory 中的框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM