Despite its rapid development, Physics-Informed Neural Network (PINN)-based computational solid mechanics is still in its infancy. In PINN, the loss function plays a critical role that significantly influences the performance of the predictions. In this paper, by using the Least Squares Weighted Residual (LSWR) method, we proposed a modified loss function, namely the LSWR loss function, which is tailored to a dimensionless form with only one manually determined parameter. Based on the LSWR loss function, an advanced PINN technique is developed for computational 2D and 3D solid mechanics. The performance of the proposed PINN technique with the LSWR loss function is tested through 2D and 3D (geometrically nonlinear) problems. Thoroughly studies and comparisons are conducted between the two existing loss functions, the energy-based loss function and the collocation loss function, and the proposed LSWR loss function. Through numerical experiments, we show that the PINN based on the LSWR loss function is effective, robust, and accurate for predicting both the displacement and stress fields. The source codes for the numerical examples in this work are available at https://github.com/JinshuaiBai/LSWR_loss_function_PINN/ .