In view of the fluorescent switching properties and anti-fatigue properties of diarylethene, a diarylethene fluorescent chemosensor for the immediate detection of zinc ion (Zn 2+ ) and magnesium ion (Mg 2+ ) in acetonitrile was synthesized in this article.The structure of 1o was determined by performing spectroscopy and elemental analysis. The presence of Zn 2+ or Mg 2+ made the chemosensor 1o show an obvious "turn-on" fluorescent signal (bright yellow-green for Mg 2+ and bright cyan for Zn 2+ ).The fluorescent change caused by the 1:1 binding of 1o and Zn 2+ or Mg 2+ might be due to hindering the excited-state intramolecular proton transfer (ESIPT) process, which were bolstered by Benesi-Hildebrand analysis, Job's plot curves, proton nuclear magnetic resonance ( 1 H-NMR) titration and mass spectrometry. The limits of detection were acquired from the standard curve plots for Mg 2+ at 44.6 nM and for Zn 2+ at 14 nM. Based on the fluorescent behaviors, a logic gate was constructed with the emission intensity at 528/518 nm as output signal, the ultraviolet-visible (UV-vis) lights, Mg 2+ /Zn 2+ and EDTA as input signals. Exogenous Zn 2+ and Mg 2+ fluorescent bioimaging were performed on Hela cells with 1o, indicating its potential application in biodiagnostic analysis. In particular, 1o was manufactured into test paper, and Zn 2+ or Mg 2+ can be conveniently, efficiently and qualitatively identified by the fluorescent color variation of the test strips.