I believe it has to do with the fact that the electrons of atoms of molecules can become 'excited' (that is, go to a higher energy level) when they are struck with light of a certain wavelength. When the electrons return to their original energy level, they emit a photon (packet of light - this is what I'm assuming we see when you see the yellowish/whiteish stain on a sheet under blacklight). I don't know if there's a way to predict which substances will respond to which light, but if there is, it's probably pretty mathematically intense.