The invention discloses a method for preparing anti-UV fabric by an in-situ method, belonging to the technical field of fabric post treatment. The method includes the steps of: weighing Ce (NO3)3.6H20, dissolving the Ce (NO3)3.6H20 in water, stirring to enable the Ce(NO3)3.6H20 to dissolve evenly so as to prepare Ce(NO3)3 solution with concentration of 1-5g/L; and adding a surfactant, aqueous ammonia and a strong oxidizer into the Ce(NO3)3 solution sequentially, stirring to be even, soaking the fabric in the solution for 10-120mins, taking out the fabric, and drying for 1-5mins at 80-180 DEG C. In this way, washable anti-UV fabric can be prepared. The weight ratio of the Ce (NO3)3.6H20, the surfactant, the aqueous ammonia and the hydrogen peroxide is 10:5-24:1-9:1-5; and the surfactant iscetyl-trimethyl ammonium bromide or dodecyl benzene sulfonic acid sodium salt. The method is simple in process and low in cost, and through the method, anti-UV fabric which can be tightly bonded withnanometer material can be prepared.