-1

是否有任何替代机制在 JSP/Servlets 而不是 javascript 中创建动态行。

JS代码:-

var table = document.getElementById('table1');  
                  var tr    = document.createElement('TR');
    var td1   = document.createElement('TD');
    var td2   = document.createElement('TD');
    var td3   = document.createElement('TD');
    var td4   = document.createElement('TD');
    var inp1  = document.createElement('INPUT');
    var inp2  = document.createElement('INPUT');
                 var inp3  = document.createElement('INPUT');
    inp1.setAttribute("Name", "purpose");
    inp1.setAttribute("id", purpose"+reclength); 
    inp2.setAttribute("Name", "Amount");
    inp2.setAttribute("id", "Amount"+reclength);  
    inp3.setAttribute("Name", "dt");
    inp3.setAttribute("id", "dt"+reclength);  
    var deleteIcon     = document.createElement('IMG');
    deleteIcon.setAttribute('src', '<%=basePath%>images/cancelIcon.gif');
    deleteIcon.onclick = function(){
        removeWthDrwls(tr);
    }
    table.appendChild(tr);
    tr.appendChild(td1);
    tr.appendChild(td2);
    tr.appendChild(td3);
    td1.appendChild(inp1);
    td2.appendChild(inp2);
    td3.appendChild(inp3);
    td3.appendChild(space2);
    td3.appendChild(deleteIcon);

但是如果用户禁用了 javascript。那么在 Java Web 应用程序中为他/她提供替代解决方案的最佳方法是什么?

4

1 回答 1

0

当然你可以在jsp中做同样的事情,参考JSP:创建动态表

这里的例子给出了如何在jsp中创建一个表,就像你可以创建动态行一样。

通过在 TR 标记中嵌套另一个 for 循环,可以为每一行添加十列,如下所示:

<TABLE>
<% for(int row=1; row <= 5; row++) { %>
    <TR>
<%      for(int col=1; col<=10; col++) { %>
        <TD> (<%=col%>, <%=row%>)
        </TD>
        <% } %>
    </TR>
<% } %>
</TABLE>

每个单元格都包含其行号和列号作为元组 (col, row)。

于 2012-06-27T06:23:08.977 回答