gpt4 book ai didi

javascript - Uncaught ReferenceError : platform is not defined

转载 作者:行者123 更新时间:2023-12-03 05:35:16 26 4
gpt4 key购买 nike

是的,所以我最近选择了 javascript 作为另一种要学习的语言。我正在一个 friend 的网站上工作,我们需要保留平台操作系统的日志,以便我们可以对统计数据进行评级。

我收到错误 Uncaught ReferenceError: platform is not Define at get_platform (eval at (file:///C:/Users/*****/Desktop/Project/index.html:2:9), : 1:191)

有人知道我该如何解决这个问题吗?任何帮助是极大的赞赏!

这是我的代码。

function get_platform(os_name) {
var os_str = os_name;
var chk_win = os_str.substr(0, 3);
if (chk_win == "Win")
platform = "win";
if (chk_win == "Lin")
platform = "linux";
if (chk_win == "X11")
platform = "unix";
return platform};
function get_os() {
var OSName = "Unknown";
if (window.navigator.userAgent.indexOf("Windows NT 6.3") != -1)
OSName = "Windows 8.1";
if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1)
OSName = "Windows 8";
if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1)
OSName = "Windows 7";
if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1)
OSName = "Windows Vista";
if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1)
OSName = "Windows XP";
if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1)
OSName = "Windows 2000";
if (window.navigator.userAgent.indexOf("Mac") != -1)
OSName = "Mac/iOS";
if (window.navigator.userAgent.indexOf("X11") != -1)
OSName = "UNIX";
if (window.navigator.userAgent.indexOf("Linux") != -1)
OSName = "Linux";
return OSName};

最佳答案

试试这个...看起来变量平台尚未正确定义。

function get_platform(os_name) {
var os_str = os_name;
var chk_win = os_str.substr(0, 3);
var platform = "";
if (chk_win == "Win")
platform = "win";
if (chk_win == "Lin")
platform = "linux";
if (chk_win == "X11")
platform = "unix";
return platform
};

注意上面添加的这一行;您可以这样定义它或添加“默认”选项:

var platform = "";

关于javascript - Uncaught ReferenceError : platform is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40756647/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com