Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中将信息传递给变量的html表单_Javascript_Html_Forms_Variables - Fatal编程技术网

在javascript中将信息传递给变量的html表单

在javascript中将信息传递给变量的html表单,javascript,html,forms,variables,Javascript,Html,Forms,Variables,我是Javascript新手,我正在尝试向html页面添加一个表单,将输入信息发送到一个变量,以便稍后使用该变量。。它取代了将信息保存到变量的输入提示。有人知道怎么做吗 总结 我假设您使用的是一个站立输入控件,让我们假设文本。。。首先,您必须将表单放入HTML中,因此在我们的JavaScript中,我们可以使用其id找到输入。我们还需要一个按钮,一个常规按钮,而不是提交按钮,以便用户在决定提交输入时单击。我们将附加一个click事件,这样当用户单击时,我们的JavaScript开始工作,因此下面

我是Javascript新手,我正在尝试向html页面添加一个表单,将输入信息发送到一个变量,以便稍后使用该变量。。它取代了将信息保存到变量的输入提示。有人知道怎么做吗

总结 我假设您使用的是一个站立输入控件,让我们假设文本。。。首先,您必须将表单放入HTML中,因此在我们的JavaScript中,我们可以使用其id找到输入。我们还需要一个按钮,一个常规按钮,而不是提交按钮,以便用户在决定提交输入时单击。我们将附加一个click事件,这样当用户单击时,我们的JavaScript开始工作,因此下面是HTML的开始:

<input type="text" id="input">
<button onclick="setClick()">
    Submit
</button>
完整代码
HTML不会将数据发送到JavaScript。但是JavaScript可以检查HTML元素并从中获取数据。你有没有试过?很多介绍性的JavaScript教程将展示如何获取HTML元素并从中提取一些信息。这正是我的意思!谢谢你的回答!没问题;。当我还在学习JavaScript的时候,我感觉就像你一样,谷歌搜索不起作用;我不知道该找什么!
function setClick()
{
    var input = document.getElementById('input').value; 
    //saves the current value of the textbox into the input variable
    alert(input);
}
/*
    So now each time the button is clicked the variable "input" is assigened
    the textbox's value
*/
<!DOCTYPE html>
<html>
<head>
<title>
Submit
</title>
<script type="text/javascript">
function setClick()
{
    var input = document.getElementById('input').value; 
    //saves the current value of the textbox into the input variable
    alert(input);
}
    /*
    So now each time the button is clicked the variable "input" is assigened
    the textbox's value
    */
</script>
<body>
<input type="text" id="input">
<button id="submit" onclick="setClick()">
    Submit
</button>
</body>
</html>