gpt4 book ai didi

javascript - 每次在 javascript 中运行函数时创建一个新的唯一全局变量

转载 作者:数据小太阳 更新时间:2023-10-29 04:59:26 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Javascript dynamic variable name

一个非常基本的问题。每次调用函数时,我都想创建一个新的 javascript 全局变量。该变量应包含元素的 ID,以便我以后可以轻松访问它。

id = 2347

//this function would be called multiple times, hopefully generating a new global each time
function (id)
{
var + id = something
// I want a variable that would be named var2347 that equals something, but the above line doesn't get it.
}

在后面的函数中,我想像这样访问变量:

function two (id)
{
alert(var + id);
}

我确定我会“咚”的一声!当有人好心回答这个问题时。

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