Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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_Html_Forms - Fatal编程技术网

单击按钮时表单输入中的输入值(在Javascript中)

单击按钮时表单输入中的输入值(在Javascript中),javascript,html,forms,Javascript,Html,Forms,这里有HTML格式的表单 按钮的单击处理程序有一个问题: tes_ya(tes1); tes1没有定义,因此当调用document.getElementById(id)时,它实际上是在调用document.getElementById(undefined)(这或原始代码都会出错并完全失败) 您实际需要的是传递字符串'tes1': tes_ya('tes1'); 按钮的单击处理程序存在问题: tes_ya(tes1); tes1没有定义,因此当调用document.getElementBy

这里有HTML格式的表单


按钮的单击处理程序有一个问题:

tes_ya(tes1);
tes1
没有定义,因此当调用
document.getElementById(id)
时,它实际上是在调用
document.getElementById(undefined)
(这或原始代码都会出错并完全失败)

您实际需要的是传递字符串
'tes1'

tes_ya('tes1');

按钮的单击处理程序存在问题:

tes_ya(tes1);
tes1
没有定义,因此当调用
document.getElementById(id)
时,它实际上是在调用
document.getElementById(undefined)
(这或原始代码都会出错并完全失败)

您实际需要的是传递字符串
'tes1'

tes_ya('tes1');

最好避免单击一次

更改:

<button type="button" onclick="tes_ya(tes1);">Yes</button>
然后在JavaScript中附加一个事件处理程序,如下所示:

document.getElementById("yes-btn").addEventListener("click", copyValue);

最好避免单击一次

更改:

<button type="button" onclick="tes_ya(tes1);">Yes</button>
然后在JavaScript中附加一个事件处理程序,如下所示:

document.getElementById("yes-btn").addEventListener("click", copyValue);

天哪,是的!我觉得自己太傻了,忘了那句话。非常感谢。天哪,是的!我觉得自己太傻了,忘了那句话。非常感谢你。