Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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 如何将值从输入文本传输到按钮?_Javascript - Fatal编程技术网

Javascript 如何将值从输入文本传输到按钮?

Javascript 如何将值从输入文本传输到按钮?,javascript,Javascript,单击按钮后,我想将id=“insertValue”的值转移到函数insert()中的变量X <input id="insertValue" type="text" /> <input type="button" value="Insert" onclick="insert('x')" /> 插入(document.getElementById('insertValue').value)应该这样做 但是你的问题与ajax无关…试试这个 JS: HTML: functio

单击按钮后,我想将
id=“insertValue”
的值转移到函数
insert()
中的变量
X

<input id="insertValue" type="text" />
<input type="button" value="Insert" onclick="insert('x')" />

插入(document.getElementById('insertValue').value)
应该这样做

但是你的问题与ajax无关…

试试这个

JS:

HTML:

function insert(e){

myValue = document.getElementById('insertValue').value;

// myValue is now set to the contents of the text field 'insertValue'
// let's check it...

alert(myValue);

}
<input id="insertValue" type="text" />
<input type="button" value="Insert" onclick="insert(this)" />
e.value = myValue;