[英]Svelte Jest test case making document.getElementId as null
[英]document getelementid is returning null
我得到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>
Java 代碼在字符串緩沖區中創建 JavaScript 代碼:
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>");
2) 我已經在全球范圍內聲明了 flag=false。 我第一次驗證標志並允許輸入上面顯示的 if 塊。 但在此之后,圖像仍然顯示在下一頁。 為什么? 我需要做些什么改變?
當您使用document.getElementById
時,您不需要#
document.getElementById('toHide').style....
對於 jQuery,請嘗試:
buffer.append("\n $(\'#toHide\').hide();\n");
代替
buffer.append("\n document.getElementById(\'#toHide\').style.display='none';\n");
#
不是 id 的一部分,所以你應該使用:
document.getElementById('toHide'). 至於 jquery 部分:
$("#toHide").hide()
這次是#
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.