0

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

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

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

4

3 回答 3

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

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

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

function edit()
{
     x = document.getElementById('new').value;
     //use this X.
}
于 2013-10-06T05:25:20.967 回答
0

为什么你不通过 Jquery 尝试它是为了理解和易于实现。

Jquery Documentation

$('input[type=button]').click(function(){
alert($('#new').val());// to get input text value
    $('#new').val('xxx');//to set input text value
});

你的问题小提琴Here

于 2013-10-06T05:35:24.153 回答
0

尝试

<input type="button" value="Edit" onclick="compute(edit(document.getElementById('new').value));" />
于 2013-10-06T05:43:14.743 回答