在单独的Java脚本文件中使用.Net资源 [英] Use .Net Resource in function with separate java script file
问题描述
我想使用脚本功能,例如函数login(),因为我们支持多语言,所以登录的结果将显示来自.Net资源的最终用户消息.
I want use functions of script , like function login() , the result of login will display message for end user from .Net Resource because we support multi language.
我想不在同一视图中使用单独的Java脚本文件,因为我已经知道如何通过此脚本来实现
I want using separate java script file not in the same view , because I already know how I can do it by this script
//这是View
<script>
alert(@Resource.Layout.Msg)
</script>
但是真正想要做的是: 在单独的文件中使用此功能
but what really want to do: use this function in separate file
fucntion login(){
if($("#user").val()=="hi")
{
alert(@Resource.Layout.Msg)
}
}
推荐答案
您可以在单独的脚本标签上定义全局变量,并且仍可以在外部javascript文件上访问它.
You could define a global variable on a separate script tag and it would still be accessible on an external javascript file.
您认为;
// define a global variable in this script tag
<script>
var text = "@Resource.Layout.Msg";
</script>
// call an external script that uses the variable text
<script src="Link to your script" />
然后在您的外部脚本中输入
Then in your external script;
function Login(){
alert(text); // use the variable defined on separate script
}
这篇关于在单独的Java脚本文件中使用.Net资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!