gpt4 book ai didi

javascript - 使用按钮和文本框输入调用 javascript 函数

转载 作者:行者123 更新时间:2023-12-02 18:16:52 24 4
gpt4 key购买 nike

我的页面中有一个文本框和按钮。我有以下几套用于不同目的。

<input type="text" id="new" name="new" value="1" />
<input type="button" value="Edit" onclick="compute(edit(xxx));" />

单击按钮后,我想调用一个 javascript 函数,该函数将接收文本框中输入的值。现在我想知道如何从输入“new”中检索值并将“xxx”作为参数传递给它?

最佳答案

<input type="button" value="Edit" onClick="compute(edit(document.getElementById('new').value))" />

这就是您在 HTML 中处理它的方式。

否则您可以在 javaScript 中编写相同的代码。

function edit()
{
x = document.getElementById('new').value;
//use this X.
}

关于javascript - 使用按钮和文本框输入调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19205687/

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