html - 在 Freemarker 模板语言中单击(选中)复选框时从表中发送两个值
问题描述
<#if userDatas?? >
<form action="remove-list" method="POST" autocomplete="on" class="form-horizontal" role="form" id="form1">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th class="minwidth">select All <input type="checkbox" onchange="checkAll(this)"> </th>
<th>roll no</th>
<th>name</th>
<th>Created date</th>
<th>modified date</th>
</tr>
</thead>
<tbody>
<#list userDatas as userData>
<tr>
<td class="centered-simple"><input type="checkbox" name="entries" value="${userData.roll}" id="${userData.roll}" ></td>
<td>${(userData.roll)!notset}</td>
<td>${(userData.name)!notset}</td>
<td>${(userData.whenCreated?datetime)!notset}</td>
<td><code>${(userData.whenModified?datetime)!notset}</code></td>
</tr>
</#list>
</tbody>
</table>
<div class="btn-group btn-group-tss">
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span> Delete selected
</button>
</div>
</form>
</#if>
在上面的代码片段中,我有一个表,标题为全选、角色、名称、创建日期和修改日期。
当我单击Delete selected按钮时,显然userdata.roll值将被发送。
在这里,我想在单击复选框时同时发送userdata.roll和userdata.name 。
我尝试过,但未能成功。
请帮助我在选中复选框时如何发送这两个值。
PS:我正在使用 FTL 进行编码。
解决方案
这不仅仅是一个表格,它是一个表单,“删除选定”按钮是一个提交按钮。提交表单后,所有输入都会发送(在您的案例中发布)。
您可以在表单的任何位置添加隐藏字段
<input type="hidden" name="someParamNameHere" value="${userData.name}" />
如果您只想在单击复选框时发送此值,您可以添加一些基本的 javascript。但我建议你把逻辑放在服务器端。
推荐阅读
- html - URL 中的 `#:~:text=` 如何突出显示文本?
- python - 将列表转换为 numpy 掩码数组
- javascript - 更改状态没有按预期工作
- angular - 如何在 Angular 管道输出中添加换行符
- javascript - HTML5: video readystate === 4, 播放时静止视频挂起
- angular - 有没有办法在模板角度转换为任何类型
- dafny - dafny assert 可以处理“!false”吗
- linkedin - LinkedIn 网站分享始终显示 1 分钟阅读。有什么办法可以去掉标签吗?
- python - 如何通过发送 http 请求使用谷歌翻译
- python - 无法通过调用内部提交的存储过程来更新数据库