Repeated transcranial magnetic stimulation (rTMS) is one of the commonly used brain stimulation techniques. In order to investigate the effects of rTMS on the excitability of different types of neurons, this study is conducted to investigate the effects of rTMS on the cognitive function of mice and the excitability of hippocampal glutaminergic neurons and gamma-aminobutyric neurons from the perspective of electrophysiology. In this study, mice were randomly divided into glutaminergic control group, glutaminergic magnetic stimulation group, gamma-aminobutyric acid energy control group, and gamma-aminobutyric acid magnetic stimulation group. The four groups of mice were injected with adeno-associated virus to label two types of neurons and were implanted optical fiber. The stimulation groups received 14 days of stimulation and the control groups received 14 days of pseudo-stimulation. The fluorescence intensity of calcium ions in mice was recorded by optical fiber system. Behavioral experiments were conducted to explore the changes of cognitive function in mice. The patch-clamp system was used to detect the changes of neuronal action potential characteristics. The results showed that rTMS significantly improved the cognitive function of mice, increased the amplitude of calcium fluorescence of glutamergic neurons and gamma-aminobutyric neurons in the hippocampus, and enhanced the action potential related indexes of glutamergic neurons and gamma-aminobutyric neurons. The results suggest that rTMS can improve the cognitive ability of mice by enhancing the excitability of hippocampal glutaminergic neurons and gamma-aminobutyric neurons.