如何在html和javascript中为django模板页声明全局变量。我想让显示语言成为一个全局变量。
<script>
function onChange(){
if (xmlHttp.readyState==4 && xmlHttp.status==200) {
//request is successful. So retrieve the values in the response
display_language = xmlHttp.responseText.split(';');
alert("response: " + display_language);
}
}
</script>
<html>
<body>
{% ifequal item.lang display_language %}
{{item.text.strip}}
{% endifequal %}
</body>
</html>
JavaScript中的变量是隐式全局的,因此除非它们在函数中并以var关键字作为前缀,否则它们将是全局可访问的
这是全球性的
这也是全球性的
这是本地的
相关问题 更多 >
编程相关推荐