gpt4 book ai didi

javascript - 使用 JavaScript 函数传递变量

转载 作者:行者123 更新时间:2023-11-30 23:50:03 25 4
gpt4 key购买 nike

我正在尝试通过下面的 GetDetail 函数传递变量。我可以传递字符串/数字并且它可以正常工作。

但是我无法传递变量

detLink.onclick = new Function ("GetDetails()");
detLink.setAttribute('onclick',"javascript:GetDetails()")

最佳答案

detLink.onclick = function () { GetDetails ( parameter1, parameter2, ... );  }

这是一个anonymous function .

另请阅读The function expression (函数运算符)

函数表达式与函数声明相似且具有相同的语法

function [name]([param] [, param] [..., param]) {
statements
}

name The function name. Can be omitted, in which case the function becomes known as an anonymous function.

param The name of an argument to be passed to the function. A function can have up to 255 arguments.

statements The statements which comprise the body of the function.

关于javascript - 使用 JavaScript 函数传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1713663/

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