A method for preparing a hydrogel includes the steps of injecting a precursor with at least two alkene groups into a predetermined portion, injecting at least one specie into the predetermined portion, and performing an X-ray irradiation on the predetermined portion to induce a polymerization reaction of the precursor to form a porous hydrogel with the specie embedded inside the porous hydrogel. In one embodiment of the present invention, the specie is selected from the group consisting of nucleic acid and adhesion agent.