使用spring:来自JavaScript的消息

Rau*_*ros 6 javascript jquery spring message call

我有一个JQuery函数,它动态地在JSP中添加一个Table:

$('#add').click(function(event) {

    event.preventDefault();

$('.tabela_procurador').before
    ('<table id="tabela_nova' + i + '" class="tabela_nova"> ' +
        '<tr> ' +
            '<td colspan="4" class="subTitulo_barra"> ' +
            '<spring:message code="representante_legal" /> '+ i +' ' +
            '</td> ' +
        '</tr> ' +
      '</table>');
     i++
   });
});
Run Code Online (Sandbox Code Playgroud)

但当我添加这个表时,我失去了spring:message.

我可以做些什么让jquery认识到这个春天:消息?

小智 10

作为解决方法,将消息值放在jsp页面上的隐藏输入中.然后在你的javascript中获取它的价值.在你的情况下:

<c:set var="val"><spring:message code="representante_legal"/></c:set>
<input id="representante_legal" type="hidden" value="${val}"/>
Run Code Online (Sandbox Code Playgroud)

在您的javascript(使用jquery)中,您可以按如下方式使用它:

$('#representante_legal').val()
Run Code Online (Sandbox Code Playgroud)


cfs*_*cfs 6

jQuery无法访问spring标记.spring:message在页面发送到客户端之前处理服务器端,稍后在客户端处理javascript/jQuery.