With the development of industry, more attention has been paid to the detection of metal ions in wastewater, especially with portable detection probes. Here, we prepared a multiple shape memory hydrogel containing cucurbit[6]uril-carbon dots, which can specifically recognize Fe3+ ions and Hg2+ ions. The self-assembly binding mode between CB [6] groups and carbon dots improves the structural stability of the hydrogel. The hydrogel is light yellow in natural light; It shows brown maple in the presence of Fe3+ions and bright white in the presence of Hg2+ions, indicating the adsorption of iron and mercury ions on the hydrogel. The fluorescence quenching of hydrogel is caused by ultraviolet competitive absorption of Fe3+ ions or Hg2+ ions, and the detection limit can reach 10-7 M. This visualized gel probe facilitates the development of portable detection devices. Meanwhile, the dynamic covalent borate bonds, acylhydrazone bonds and reversible crystallization of polyvinyl alcohol chains were used to achieve the shape transformation and excellent mechanical properties of the hydrogel. This supported the need for specific shapes under extreme conditions of detection.