简体   繁体   English

Java中的JS功能的onload不起作用

[英]onload for JS Function with Java in it doesnt work

I am trying to use this: 我正在尝试使用此:

ResultSet rs1 = st.executeQuery("SELECT * FROM Termine");

window.onload = function(){
<%
    while(rs1.next()){ 
    String vname = rs1.getString(1);
    String vid = rs1.getString(2);
    System.out.println(vid+" "+vname);%>
    document.getElementById(<%=vid%>).innerHTML="<%=vname%>";
    <%
    }

But it's not working.The Results of the ResultSet are printed out immediately (whats there for test purposes), but FireBug says: TypeError: document.getElementById(...) is null . 但是它不起作用。ResultSet的结果立即打印出来(用于测试目的),但是FireBug说: TypeError: document.getElementById(...) is null The Element is a <td> , which is created in the Body of the JSP Page. 元素是<td> ,它是在JSP页面的主体中创建的。 What can i do to get it working, right when i want it to work? 我要怎么做才能使其正常工作?

Lel, The Solution was: document.getElementById("<%=vid%>").innerHTML="<%=vname%>"; Lel,解决方案是:document.getElementById(“ <%= vid%>”)。innerHTML =“ <%= vname%>”; The Double Quotes for vid were missing. vid的双引号不见了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM