如何在html和javascript中爲django模板頁面聲明全局變量。我想讓display_language成爲一個全局變量。如何在html和javascript中聲明全局變量
<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>
'window.varname = '值',' – zerkms
或'無功VARNAME = '值';'放在所有功能外將使全球JS變量,但沒有客戶端 - 方JS變量將可以從您的服務器端代碼訪問... – nnnnnn
@nnnnnn:有一天你重構代碼,並沒有注意到。並且在將某些東西移動到某個函數之後 - 您將有快樂的調試時間:) – zerkms