简体   繁体   中英

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. 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. 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. 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/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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