High-order harmonic generation with mid-infrared laser fields has been considered the most promising method to produce soft X-rays attosecond pulses, which provides an important tool for probing the ultrafast electronic dynamics in atoms, molecules, and solids in real time. However, quantum diffusion of the electron wavepacket can lead to a dramatic drop of the harmonic yield when a mid-infrared laser field is used. Here we theoretically demonstrate that a spatially structured (SS) laser field can suppress quantum diffusion of the electron wavepacket and lead to a significant enhancement of high-order harmonic generation, compared with those generated by the spatially homogeneous (SH) laser field. The SS laser field is inhomogeneous in transverse direction perpendicular to the laser polarization and homogeneous in the polarization direction of the laser field. The electric field presents a valley structure. It is found that this valley structure can confine the electron wavepacket around the parent ion, prevent the electron wavepacket spreading, and finally lead to the significant enhancement of the high-order harmonics. Our results provide a novel method for controlling the ultrafast electron wavepacket dynamics of HHG.