In this work, a polydopamine (PDA)/polyamide composite nanofiltration (NF) membrane was synthesized through continuous surface grafting and reverse interfacial polymerization (RIP) for selective separation of Mg2+/Li+. Dopamine was deposited onto the support membrane through self-polymerization. 1,3,5-benzenetricarboxylic acid chloride (TMC) was grafted through its reaction with PDA, and then RIP was performed between the residual TMC on the membrane and polyethyleneimine (PEI). The reaction process how composite membranes were formed was investigated using high-sensitivity ATR-FTIR, AFM and SEM. Compared with the single grafting or RIP reaction, the PDA-TMC-PEI composite NF membrane had a smaller pore size and higher positive charge density, which enhanced the Donnan effect in the selective separation of Mg2+/Li+. It further showed high separation capacity in a mixed salt solution with a separation factor (SLi,Mg) of 99.0 (Mg2+/Li+ mass ratio of 120), and the magnesium rejection is 98.9%, surpassing the majority of previously reported NF membrane. The pure water flux of the PDA-TMC-PEI composite NF membrane reached 6.37 L·m-2·h-1·bar-1. The static contact angle of PDA-TMC-PEI was only 10o, and the high hydrophilicity facilitated the water permeation. In addition, in a simulated salt-lake brine water treated with a three-stage NF system, the Mg2+/Li+ mass ratio was significantly reduced, from 13.08 to 0.04, and the Mg2+ concentration was reduced from 1,190 mg·L-1 to 3.7 mg·L-1, showing great potential for practical applications in lithium extraction.