A new naphthalene-containing macrocyclic triazole (1) and its acyclic compared compound (2) have been synthesized and characterized. In acetonitrile and acetonitrile aqueous solutions, 1 and 2 showed good fluorescence sensing ability to Hg2+ over other metal ions, with 1 exhibiting better sensitivity and selectivity than 2 owing to its macrocyclic effect. 1H NMR titrations and DFT calculation results showed that the N atoms of triazole and O atoms of the ether groups in 1 and 2 participate in binding during complexation with Hg2+.