Milk is an important consumer product with high nutritional value. The presence of veterinary drug residues in milk owing to the indiscriminate use of veterinary drugs may affect consumer health. In the mass spectrometric analysis of trace compounds, chromatographic co-eluting components easily interfere with the mass spectral signals obtained, affecting the accuracy of qualitative and quantitative analyses. Matrix purification is a promising method to reduce the matrix effect. Chitosan is a natural biopolymer with numerous active functional groups such as amino, acetyl, and hydroxyl groups; these groups can adsorb lipids through hydrophobic and electrostatic interactions. Chitosan also has the advantages of low production cost, stable chemical properties, and convenient modification. Novel chitosan-based materials are promising candidates for lipid purification. In this study, a chitosan membrane was modified with trimethoxyoctadecylsilane (C18-CSM). C18-CSM was prepared through one-step hydrolysis and used as a dispersive solid phase extraction (DSPE) adsorbent to purify the matrix during milk pretreatment. We combined C18-CSM with ultra-high performance liquid chromatography-quadrupole/electrostatic field orbitrap mass spectrometry (UHPLC-Q/Exactive Orbitrap MS) to develop an effective method for the extraction and determination of ofloxacin, enrofloxacin, ciprofloxacin, diazepam, and metronidazole in milk. C18-CSM was characterized using scanning electron microscopy, Fourier transform infrared spectroscopy, and water contact angle testing. The results indicated that the material has a rough surface and uniformly dense cross-section. The water contact angle of C18-CSM was 104°, indicating its good hydrophobicity. The pretreatment conditions (extraction solvent, dosage of NaCl, extraction frequency, and dosage of C18-CSM) that influenced the recoveries of the five veterinary drugs were investigated in detail. The optimal conditions were established as follows: 5% formic acid in acetonitrile, 1 g NaCl, extraction 1 time, 20 mg C18-CSM. Separation was performed on a Hypersil GOLD VANQUISH column (100 mm×2.1 mm, 1.9 μm). The mobile phase consisted of 0.1% formic acid aqueous solution and 0.1% formic acid in acetonitrile, and was flowed at a rate of 0.3 mL/min. The sample injection volume was 1 μL, and the column temperature was maintained at 25 ℃. Mass spectrometric analysis was performed in positive electrospray ionization mode. To verify the necessity of the purification material, the matrix effect was investigated using the matrix-matched standard curve method. The use of C18-CSM reduced the matrix effects of the five necessity drugs from the range of -22%-8.8% to the range of -13%-3.6%, indicating that C18-CSM is a highly efficient DSPE material. Under optimal conditions, the developed method showed good linearities within the range of 0.5-100 μg/L, with correlation coefficients (r2)≥0.9970. The limits of detection(LODs) and quantification (LOQs) were 0.2 μg/L and 0.5 μg/L, respectively. To assess the accuracy and precision of the method, we prepared milk samples with three spiked levels (low, medium, and high). The recoveries of the five veterinary drugs were ranged from 79.5% to 115%, and the intra-day and inter-day relative standard deviations were 7.0%-13% (n=6) and 1.3%-11% (n=3), respectively. This study provides a simple, accurate, and reliable method for the rapid and simultaneous determination of the five veterinary drug residues in milk.