javascript - Save button not responding- why DOM is null after I fill out data on UI
问题描述
Now I have a save button that's not working. When I click on it nothing happens on UI.
<img src="/something/image/Save.jpg" border="0" style="cursor:hand" alt="Save"
onclick="if(validate_edit()){pop_comment('edit');}">
function pop_comment(src)
{
//document.all.comment.value=document.getElementsByTagName('comment');
window.showModalDialog("./jsp/util/comment.jsp?src="+src, window, "dialogHeight=320px; dialogWidth=500px; dialogLeft=100px; dialogTop=150px; resizable=yes; status=no;scroll=no;");
}
After I click on Save button I see below error on console:
violator_edit.do:354 Uncaught TypeError: Cannot read property 'value' of null
at validate_edit (edit.do:354)
at HTMLImageElement.onclick (edit.do:1035)
and says this line in validate_edit() caused the error:
var state = document.getElementById('wsbean.state').value;
I wrote this test:
if(document.getElementById('wsbean.state')==null)(console.log("null"))
Result:
null
So the DOM object is not ready. But why? I did fill out state on UI. Could it be because of the script tag position? the HTML of the page looks like this:
<html>
<head></head>
<body>
<Script></Script>
<div></div>--> the whole form is inside this div
</body>
</html>
解决方案
推荐阅读
- microservices - 微服务模式:事务日志跟踪与轮询发布者
- logging - Sarg 没有每天正确生成单独的报告
- python - 在 python 2 字符串中打印“delta”希腊符号(Δ)
- excel - VBA 是否可以识别带有公式的行并仅自动填充这些行?
- security - 为 SHE 模块重新编程内存/密钥时,不会从 M1||M2 生成正确的 M3
- asp.net - SignalR 错误 405 - 这个错误告诉我什么?
- javascript - 为什么 Ajax 和 SweetAlert 不显示?
- java - CXFServlet 抛出 java.lang.NoSuchMethodError: org.codehaus.stax2.ri.EmptyIterator.getInstance()Lorg/codehaus/stax2/ri/EmptyIterator;
- angular - 使用多个有序的异步服务
- ionic-framework - 有没有一个编辑器可以让你为 Ionic 设计像 Xcode 这样的 UI?