如何将值从jQuery方法赋值给Spring mvc form标记中的隐藏字段

时间:2018-02-14 21:21:12

标签: javascript jquery spring-mvc

我需要将浏览器时区传递回我的控制器,并且我通过在jsp中使用隐藏的表单字段来完成此操作。我使用jQuery val方法设置值。但是,在Controller上检索的值是""。你能帮忙吗?

JSP - Spring表单标签: `

<div data-role="content" style="text-align: center">
        <form:form id="user" modelAttribute="user" action="index">
            <form:input path="accountNumber" id="account-number" 
                placeholder="Account Number"/>
            <form:hidden path="timeZone" id="timeZone"  value=""/>
        </form:form>
</div>

`

jQuery方法: $(document).ready(function() { var zone = Intl.DateTimeFormat().resolvedOptions().timeZone; $("#timeZone").val(zone); });

0 个答案:

没有答案