简体   繁体   中英

Save checked checkboxes javascript

I have a Website at work which is being used As a settings page. It contains about 200 checkboxes. Is there an easy way to somehow Save the checkboxes which are checked and send them to a coworker for him to be able to automaticaly get the correct settigns? I was able to find a javascript which after enterin in the adress bar checked/unchecked all and thought that there might be an elegant way to check the needed ones instantly.

This is pretty hacky, and all console based, but you could do something like this...

Each checkbox would have to have a name... or replace name for id...

var arr = [];
$('input:checked').each(function(){
    arr.push($(this).attr('name'));
});

Then you could take the output of arr and give him that with a short script to check the boxes.

var arr = ["name1"];
arr.forEach(function(v){
    $('input[name="'+v+'"]').prop('checked',true);
});

I hope this helps.

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