文档getelementid返回null

Tec*_*ind 2 javascript jquery

我得到的document.getElementById("#toHide")是null.怎么解决这个?如何将此语句转换为jquery?

HTML:

<form wicket:id="safeForm" class="clearfix" />
<div id="toHide" class="pb-text-align-center">
<img id="loadingImg" src="my image location" style="margin-left: auto; margin-right: auto;"/>
</div>  
Run Code Online (Sandbox Code Playgroud)

在字符串缓冲区中创建JavaScript代码的Java代码:

if(flag == false){
    flag = true;
    buffer.append("$('#toHide').doTimeout(1000, ");
    buffer.append("function() { ");
    buffer.append("$('#").append(component.getMarkupId()).append("').submit(");     
    buffer.append(");");
    buffer.append("$('#toHide').html('<img id=\"loadingImg\" src=\"../../img/load.gif\" style=\"margin-left: auto; margin-right: auto;\"/>'); ");
    buffer.append("});\n");
    }
    else{
       buffer.append("\n document.getElementById(\'#toHide\').style.display='none';\n");    
    }
    buffer.append("</script>");
Run Code Online (Sandbox Code Playgroud)

2)我在全球范围内声明了flag = false.我正在第一次验证标志并允许输入上面显示的块.但在此之后,图像仍显示在下一页.为什么?我需要做些什么改变?

nic*_*ckf 6

当你使用时,document.getElementById你不需要#

document.getElementById('toHide').style....
Run Code Online (Sandbox Code Playgroud)