【发布时间】:2019-03-26 13:43:51
【问题描述】:
我必须创建一个包含所有行的表格,删除或更新产品的价格。我编写了以下代码,但它将tr 标记显示为无效位置。此外,该表格也无法按要求工作。
<h1>On Manage Products Page by <% out.println(request.getSession().getAttribute("username"));%></h1>
<div align="center">
<script>
function onSubmitForm()
{
System.out.println(document.pressed);
if(document.pressed == 'delete')
{
System.out.println("delete");
document.myForm.action ="deleteProduct.do";
}
else
if(document.pressed == 'update')
{
System.out.println("update");
document.myForm.action ="updateProduct.do";
}
return true;
}
</script>
<table>
<thead><tr><th>PRODUCT NAME<th>PRODUCT PRICE<th> DELETE<th COLSPAN="2"> UPDATE
<% List products=(List)request.getSession().getAttribute("products"); %>
<c:forEach items="${products}" var="product">
<form name="myForm" onsubmit="return onSubmitForm();">
<input type="hidden" name="productID" value="${product.getProductID()}" />
<tr>
<td>${product.getProductName()}
<td>${product.getProductPrice()}
<td><input type="submit" name="operation" onclick="document.pressed=this.value" value="delete"/>
<td><input type="text" name="updatedPrice"/>
<td><input type="submit" name="operation" onclick="document.pressed=this.value" value="update"/>
</form>
</c:forEach>
</table>
</div>
【问题讨论】:
-
你有一个没有关闭的
标签。一个未关闭的 ......一个未关闭的 thead ......您拥有一个表单标签作为表格元素的子元素......您生成的代码有很多问题。 结束标签哟! :)
标签: javascript forms html-table