Aside from not taking things apart in the first place, that for many of us is not a reasonable suggestion, the solution is a simple magnet.
Using a small magnet you can easily retain screws for the rebuild.
Better yet, use a number of magnets and you can organize your screws based on what stage in the disassembly they came from. That's a useful thing to know.
Here's a tip though, when you put magnets side by side reverse the polarity (flip them) of every other magnet so that they don't hurtle towards their neighbour like knights jousting.
This simple trick will save you a headache or two.
Get yourself some small plastic closable bags to store and label screws that you intend on putting back 'someday'. If you're like me those screws will never likely return home, but at least you will know where they once came from.