【问题标题】:How to pass hidden value from jQuery to Spring MVC controller without Ajax如何在没有 Ajax 的情况下将隐藏值从 jQuery 传递到 Spring MVC 控制器
【发布时间】:2015-12-27 22:54:35
【问题描述】:

我有下表

    <table id="table">
            <thead>
            <tr>
                <th></th>
               ...
            </tr>
            </thead>
            <tbody>
            <c:choose>
                <c:when test="${not empty userList}">
                    <c:forEach var="user" items="${userList}">
                        <tr>
                            <td><input name="id" value="${user.id}" hidden></td>
                            ...
                        </tr>
                    </c:forEach>
                </c:when>
            </c:choose>
            </tbody>
        </table>
<input type="button" name="objects"/>

这是我的 javascript 在我的表格中选择行

$(window).load(function () {
    $("#table tr").click(function () {
        $(this).addClass('selected').siblings().removeClass('selected');
        var elem = $(this).find('td:first input').attr('value');
    });

    $('.objects').on('click', function (e) {
        alert($("#table tr.selected td:first input").attr('value'));
    });
});

当我选择行然后按下按钮 objects 时,我会收到所选 ID 的警报。我想在 Spring MVC 控制器中传递这个 id,不需要 Ajax。

所以我想在表格中选择用户,然后按下按钮 objects 并将所选用户的 id 传递到新页面 /userObjects。请你帮我解决这个问题。

【问题讨论】:

    标签: javascript jquery spring spring-mvc


    【解决方案1】:

    删除您的alert,然后执行以下操作:

    var id = $("#table tr.selected td:first input").attr('value');
    window.location = '/userObjects?id=' + id;
    

    您可能需要根据您要转发用户的网址调整window.location

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-28
      • 2012-01-19
      • 2013-01-20
      • 1970-01-01
      • 2012-02-19
      • 2013-12-13
      • 2019-12-17
      • 1970-01-01
      相关资源
      最近更新 更多