【问题标题】:Send two values from table when a checkbox is clicked (checked) in Freemarker Template Language在 Freemarker 模板语言中单击(选中)复选框时从表中发送两个值
【发布时间】:2018-10-17 15:15:15
【问题描述】:
        <#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>

在上面的代码sn-p中,我有一个表格,标题为全选、角色、名称、创建日期和修改日期。

当我点击 Delete selected 按钮时,显然 userdata.roll 值将被发送。

这里我想在单击复选框时同时发送 userdata.rolluserdata.name

我试过了,但没有成功。

请帮助我如何在选中复选框时发送这两个值。

PS : 我正在使用 FTL 编码。

【问题讨论】:

    标签: html checkbox html-table freemarker


    【解决方案1】:

    这不仅仅是一个表格,它是一个表单,“删除所选”按钮是一个提交按钮。提交表单后,所有输入都会发送(在您的案例中发布)。

    您可以在表单的任意位置添加隐藏字段

    <input type="hidden" name="someParamNameHere" value="${userData.name}" />
    

    如果您只想在单击复选框时发送此值,您可以添加一些基本的 javascript。但我建议你把逻辑放在服务器端。

    【讨论】:

    • 谢谢,您能否帮我解释一下仅在单击复选框时才发送此值的逻辑。
    猜你喜欢
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    相关资源
    最近更新 更多