您的位置:首页 > Web前端 > JavaScript

Making use of localized variables in javascript.

2013-05-31 09:53 309 查看
Here is a simple way of using values stored in global resource files to be used in your markup and javascript code. Simply add the following to your markup (aspx page, user control or whatever).

<script type="text/javascript">
var myVariable = '<%= GetGlobalResourceObject("MyResourceFileName", "MyResourceKey").ToString()%>';
</script>


Once this is done, you can make use of the variable in your javascripts.

Note: These variables cannot be added in separate javascript files, but have to be added to the page directly. However, once added, they can be reached from code in the javascript file if it is imported.

EDIT: The GetGlobalResourceObject method is a standard method in the HttpContext class (link here).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: