问题
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.
I want using separate java script file not in the same view , because I already know how I can do it by this script
// this is 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)
}
}
回答1:
You could define a global variable on a separate script tag and it would still be accessible on an external javascript file.
In your view;
// 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
}
来源:https://stackoverflow.com/questions/61318084/use-net-resource-in-function-with-separate-java-script-file