如何在 document.getElementById() 上添加样式

ABM*_*lib -2 javascript css

我有一个加载程序图像显示在 iFrame 的左角,但是,我试图在中心显示。您能否建议如何在以下代码中添加样式:

var ShowLoader = function() {
    document.getElementById("mainIframe").style.display = "none";
    document.getElementById("documentIframe").src = "http://localhost:63902/images/loading.gif";
}
Run Code Online (Sandbox Code Playgroud)

小智 7

使用下面的代码居中对齐。

document.getElementById("documentIframe").style.textAlign = "center";
document.getElementById("documentIframe").style.margin = "0px auto";
Run Code Online (Sandbox Code Playgroud)