我的 JavaScript 文件中有这样的代码 x.js

alert("<spring:message code='plants.selectedPlant.name' javaScriptEscape='true' />"); 

在文件中messages.properties我有一行:

plants.selectedPlant.name = Roses 

但它只是提醒文本 <spring:message code='plants.selectedPlant.name' javaScriptEscape='true' />但不是值(value)。

我没有在 JS 文件中导入任何内容。

请您参考如下方法:

一个有用的技巧是执行以下操作:

HTML

<span id="selectedPlantName" display="none"> 
    <spring:message code='plants.selectedPlant.name' javaScriptEscape='true' /> 
</span> 

JS(假设您使用 jQuery)

alert($("#selectedPlantName").text()); 

或者

看看这个问题中接受的答案:

Resolving spring:messages in javascript for i18n internationalization


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!