The paper studies the validity of Maxwell equation in the case for coexistence of electromagnetic field and gravitational field. With the algebra of quaternions, the Newton's law of gravitation is the same as that in classical theory of gravitational field. Meanwhile the Maxwell equation is identical with that in classical theory of electromagnetic field. And the related conclusions can be spread to the case for coexistence of electromagnetic field and gravitational field by the algebra of octonions. The study claims that Maxwell equation keeps unchanged in the case for coexistence of gravitational field and electromagnetic field, except for the direction of displacement current.