The prompt emission of most gamma-ray bursts (GRBs) typically exhibits a non-thermal Band component. The synchrotron radiation in the popular internal shock model is generally put forward to explain such a non-thermal component. However, the low-energy photon index $alpha sim -1.5$ predicted by the synchrotron radiation is inconsistent with the observed value $alpha sim -1$. Here, we investigate the evolution of a magnetic field during propagation of internal shocks within an ultrarelativistic outflow, and revisit the fast cooling of shock-accelerated electrons via synchrotron radiation for this evolutional magnetic field. We find that the magnetic field is first nearly constant and then decays as $Bpropto t^{-1}$, which leads to a reasonable range of the low-energy photon index, $-3/2 < alpha < -2/3$. In addition, if a rising electron injection rate during a GRB is introduced, we find that $alpha$ reaches $-2/3$ more easily. We thus fit the prompt emission spectra of GRB 080916c and GRB~080825c.