Addressing the challenge of eliminating bacteria and stimulating osteogenesis in infectious bone defects, where cells and bacteria coexist within the microenvironment, presents a significant hurdle. In this study, a strategy of targeting bacteria is proposed to address this challenge. For this purpose, a methacrylated gelatin composite hydrogel containing zinc ion and D-type cysteine-modified polydopamine nanoparticles (PZC) is developed. The D-cysteine, involved in the metabolism of the bacterial peptidoglycan chain, allows PZC to specifically target bacteria, exhibiting a form of "disguise strategy". Through the targeting effect, this composite hydrogel can selectively kill bacteria and promote osteogenesis combing photothermal therapy with Zn2+ release, which showcases spatial controllability. Moreover, the antibacterial ability will be further improved after Near-infrared light irradiation. The multifunctional hydrogel containing Zn2+ modified nanoparticles can also promote osteogenic differentiation of bone marrow stem cells. Animal studies have revealed that the multifunctional hydrogel can inhibit bacteria growth and promote repair of infectious bone defects in rats. Findings from this study imply that endowing the nanoparticles with bacteria-targeting function can precisely control the events in cells and bacteria in the complex microenvironment, which can provide insights for the treatment of complex diseases with antibacterial requirements.