在js中读取properties文件
2017-11-17 09:38
232 查看
本文转自http://blog.csdn.net/zmx729618/article/details/52610870
假设有JavaScript文件叫做:readproperties.js,这个文件需要读取config.properties这个配置文件,步骤如下:1、 下载插件jquery.i18n.properties-min-1.0.9.js,在eclipse中放到合适的目录下。由于需要jQuery的支持,所以也需要jquery插件,在这里选择jquery-1.7.1.min.js(jquery.i18n.properties-min-1.0.9.js这个插件对jQuery没有版本要求,可以使用任何版本的jQuery插件),如下图所示:
2、 在引入readproperties.js的JSP文件中做如下声明:
[html]
view plain
copy
print?
![](https://code.csdn.net/assets/CODE_ico.png)
<script src=“js/jquery-1.7.1.min.js” language=“javascript”>
</script>
<script type=“text/javascript” src=“js/jquery.i18n.properties-min-1.0.9.js”>
</script>
![](http://static.blog.csdn.net/images/save_snippets.png)
[html] view plain copy print?<script src=“js/jquery-1.7.1.min.js” language=“javascript”>
</script>
<script type=“text/javascript” src=“js/jquery.i18n.properties-min-1.0.9.js”>
</script>
<script src="js/jquery-1.7.1.min.js" language="javascript"> </script> <script type="text/javascript" src="js/jquery.i18n.properties-min-1.0.9.js"> </script>
其中的路径根据实际情况作出调整。
3、在readproperties.js中,编写如下函数获取properties文件中的值:
[javascript]
view plain
copy
print?
![](https://code.csdn.net/assets/CODE_ico.png)
function loadProperties(){
jQuery.i18n.properties({// 加载properties文件
name:’ISPindex’, // properties文件名称
path:’i18n/’, // properties文件路径
mode:’map’, // 用 Map 的方式使用资源文件中的值
callback: function() {// 加载成功后设置显示内容
alert($.i18n.prop(“isp_index”));//其中isp_index为properties文件中需要查找到的数据的key值
}
});
}
![](http://static.blog.csdn.net/images/save_snippets.png)
[javascript] view plain copy print?function loadProperties(){
jQuery.i18n.properties({// 加载properties文件
name:’ISPindex’, // properties文件名称
path:’i18n/’, // properties文件路径
mode:’map’, // 用 Map 的方式使用资源文件中的值
callback: function() {// 加载成功后设置显示内容
alert($.i18n.prop(“isp_index”));//其中isp_index为properties文件中需要查找到的数据的key值
}
});
}
function loadProperties(){ jQuery.i18n.properties({// 加载properties文件 name:'ISPindex', // properties文件名称 path:'i18n/', // properties文件路径 mode:'map', // 用 Map 的方式使用资源文件中的值 callback: function() {// 加载成功后设置显示内容 alert($.i18n.prop(“isp_index”));//其中isp_index为properties文件中需要查找到的数据的key值 } }); }
其中properties文件的路径、名称等需要根据实际情况作出调整。本例中properties文件放在如下图所在位置。
这样运行该函数时,即可显示需要的数据了。
如果本文说的不够清楚,可以参考API文档:www.ibm.com/developerworks/cn/web/1305_hezj_jqueryi18n/
相关文章推荐
- jsp/js读取properties文件的方法
- 分别用Java和JS读取Properties文件内容
- jsp中读取properties文件 (jsp中读取properties文件,并把值设到js变量中)
- 分别用Java和JS读取Properties文件内容
- 分别用Java和JS读取Properties文件内容
- java读取配置文件Properties
- Java web项目中读取properties,xml文件
- java 读取properties文件
- Spring-读取properties文件
- Node.js读取文件
- 在Action中获取项目的服务器路径and读取配置文件common.properties
- Java Properties 类读取配置文件信息
- Java Properties 类读取和修改配置文件信息
- Android中读取properties文件
- Java配置文件Properties的读取、写入与更新操作
- fmt 国际化格式标签库(读取application.properties文件)
- 读取properties文件的工具类
- springboot之读取properties属性文件
- Java读取Properties文件的六种方法
- java读取配置文件(properties)的时候,unicode码转utf-8