A new fluorescent probe 1O was synthesized through linking diarylethene and Quinoxaline-2-hydraqzide group, probe 1O showed a selective "off-on" fluorescent response toward Mg 2+ . In the presence of Mg 2+ , the probe 1O displayed a distinct change of fluorescence color, from dark to green, the fluorescence intensity increased 6.8-fold, and meanwhile, emission peak has a significant blue shift, which was shifted from 524 nm to 518 nm. Then, on account of the fluorescence properties of compound 1O, we designed a logic gate. On top of that, probe 1O also can be successfully used to monitor Mg 2+ of the actual water samples.