帮助从 HTML 表格中删除字段
所以我不确定如何标记这个,但基本上我有一个动态加载的 HTML 表,其中包含可以删除的值,目前我正在使用复选框让用户决定要删除哪一行。到目前为止,这是我的代码:
<table id="comments" align="center" width="59%">
<thead>
<th class="headerClass" width="7%">Delete</th>
<th width="15%" class="headerClass">Date</th>
<th class="headerClass" width="15%">Employee</th>
<th class="headerClass">Comment</th>
</thead>
<tbody>
<%
while (result.next()) {
commentDate = StringUtils.defaultString(result.getString("commentDate"));
commentUser = StringUtils.defaultString(result.getString("cName"));
comment = StringUtils.defaultString(result.getString("xbs_comment"));
%>
<tr>
<td class="normal"><input type="checkbox" class="checkbox" /></td>
<td class="normal"><%=commentDate%></td>
<td class="normal"><%=commentUser%></td>
<td class="normal" width="68%"><%=comment%></td>
</tr>
</tbody>
</table>
<label for="comment"><h4>Add a Comment:</h4></label>
<textarea cols="105" id="comment" name="comment" rows="4"></textarea>
<br />
<div align="center" class="submit">
<input class="submit" width="10%" type="submit" name="submit" id="submit" value="Submit" />
</div>
基本上我有一个带有评论的表格,用户可以使用提交按钮添加评论,但我希望他们也能够使用复选框来删除评论。我是否需要另一个带有删除按钮的表单标签,或者我可以只使用这个提交按钮吗?另外,如果我确实保留了复选框,我如何让程序的后端(函数和 servlet)知道选中了哪个?感谢您的帮助!
So I am not sure exactly how to tag this one, but basically I have a dynamically loaded HTML table, that contains values that will can be deleted, currently I am using check boxes for the user to decide which row to delete. Here is my code so far:
<table id="comments" align="center" width="59%">
<thead>
<th class="headerClass" width="7%">Delete</th>
<th width="15%" class="headerClass">Date</th>
<th class="headerClass" width="15%">Employee</th>
<th class="headerClass">Comment</th>
</thead>
<tbody>
<%
while (result.next()) {
commentDate = StringUtils.defaultString(result.getString("commentDate"));
commentUser = StringUtils.defaultString(result.getString("cName"));
comment = StringUtils.defaultString(result.getString("xbs_comment"));
%>
<tr>
<td class="normal"><input type="checkbox" class="checkbox" /></td>
<td class="normal"><%=commentDate%></td>
<td class="normal"><%=commentUser%></td>
<td class="normal" width="68%"><%=comment%></td>
</tr>
</tbody>
</table>
<label for="comment"><h4>Add a Comment:</h4></label>
<textarea cols="105" id="comment" name="comment" rows="4"></textarea>
<br />
<div align="center" class="submit">
<input class="submit" width="10%" type="submit" name="submit" id="submit" value="Submit" />
</div>
Basically I have a table with comments, the user can add a comment using the submit button, but I would like them to also be able to use the check box to delete comments. Do i need another form tag w/ a delete button, or can I use just this one submit button? Also if I do stay with the check boxes, how do I let the back end of my program(function and servlet) know which was checked? Thanks for any help!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以与相同的提交一起执行此操作。您也可以通过ajax删除评论,删除成功后可以重新加载页面。
以下是使用同一提交按钮删除评论的一些方法。我假设用户有权删除表中的所有评论。
为此,您必须在复选框上分配一个对于每条评论都是唯一的值。通常是表示每条评论的行中的主键或 ID。
对每个复选框使用单个名称来执行多次删除。下面的示例
comments.jsp
这只是一个示例,因此请更多地关注有复选框的部分。
addDelete.jsp
现在,在 adddelete.jsp 上,您可以有两个具有不同功能的查询。第一个是添加新评论,第二个是删除评论。
要获取要删除的评论列表,请将其存储在数组中。并且还获取其他字段。
除了这一部分之外,我希望您能够处理完成您想做的事情所需的功能。
You can do this along with the same submit. And also you can delete comment via ajax then you may reload the page upon success in deletion.
Here is some of the way to delete the comment by using the same submit button. And I assume that the user has the access to delete all the comments in the table.
To do this you must assign a value on the checkbox that are unique for every comments. Usually the primary key or ID in the row that represent each comment.
Use a single name for every checkbox to do a multiple delete. Sample below
comments.jsp
This is just an example, so focus more on the part where have a checkbox.
addDelete.jsp
Now on the adddelete.jsp, you could have two queries with different function. first is for adding new comments and second is the deletion of the comment(s).
To get the list of comment to be delete store it in an array. And also get the other fields.
Beyond this part I hope you can handle what function you will need to do what you want.