Using the finite-differences method, the electronic structures of two-dimensional electrons are investigated under a periodic magnetic field. To achieve accuracy, the exact profile of the magnetic field is employed in the numerical calculations. The results show that the system exhibits rich band structures, and the width of sub-bands becomes narrower as |ky| increases. In particular, many bound states are formed in the potential wells, and they are localized. Localization analysis confirms that extended, localized, and intermediate states coexist in the system, which is very different from the case without the modulated magnetic field. These results may help us to learn more about two-dimensional electrons in a periodic magnetic field.