【发布时间】:2018-02-22 14:08:42
【问题描述】:
我被困住了。我真的不知道自己做错了什么,但我无法将字符串返回到嵌入式 Javascript 中的变量。
token.js:
function token () {
return "mysecretstring";
}
HTML 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>TXTURE Server Status</title>
<script src="http://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
token_val="";
$.getScript('./token.js', function(data) {
token_val = token();
console.log("function: " + token_val);
});
</script>
</head>
<body>
</body>
</html>
我可以做任何我想做的事,token_val 仍然是空的。任何提示表示赞赏。
最好的问候,托马斯
【问题讨论】:
-
console.log 是否显示正确的值?你想在哪里使用
token_val?
标签: javascript jquery html getscript