In this article, to guarantee the good tracking performance of the precision motion system for various tracking tasks, an online iterative learning compensation method is proposed for closed-loop motion control systems. The prediction model is based on the closed-loop model of the linear second-order system with a proportional-integral-derivative controller, and an estimation term is added to deal with the influence of slow-varying uncertain disturbances. On the basis of the accurate state prediction, the dynamical feedforward compensation can be obtained, which suppresses the tracking error caused by the dynamical lag. Furthermore, in order to simultaneously compensate the errors caused by nonlinear factors such as uncertain disturbances and to guarantee the smoothness of the compensated trajectory, the optimal compensation gain is determined through online iterative calculation. The online iterative approach is similar to iterative learning control, but does not require several offline iterations of a repeating trajectory. Comparative experiments are carried out on an industrial motion stage. Various experimental results consistently demonstrate that the proposed compensation scheme can achieve the tracking accuracy comparable to iterative learning, while maintaining the robustness to trajectory changes and uncertain disturbances without reoffline iteration.