Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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_Jquery_Html_Input - Fatal编程技术网

Javascript 脚本-检索文本输入

Javascript 脚本-检索文本输入,javascript,jquery,html,input,Javascript,Jquery,Html,Input,我的html中有几个输入(这是一个输入示例): 但是不要工作。我的警报不显示。你能帮我吗 PS:这是Javascript或jQuery中的脚本吗?如果输入中缺少id属性,只需将html更改为包含 <input id="designation" name="designation" type="text" size="12" /> 1)在您的脚本中,您可以通过id指定来获取值,但您没有在html输入字段中添加id属性,如指定。因此,只有它抛出未定义的错误 $(“#编译”)。单击(

我的html中有几个输入(这是一个输入示例):

但是不要工作。我的警报不显示。你能帮我吗


PS:这是Javascript或jQuery中的脚本吗?

如果输入中缺少id属性,只需将html更改为包含

<input id="designation" name="designation" type="text" size="12" />

1)在您的脚本中,您可以通过id指定来获取值,但您没有在html输入字段中添加id属性,如指定。因此,只有它抛出未定义的错误

$(“#编译”)。单击(函数(){
var n_input=document.getElementById(“名称”).value;
警报(“名称:”+n_输入);
});


在HTML中有一个
id='designation'
你应该使用
getElementsByName()
而不是
getElementById()
id或name更好?或者它们是相同的?
$("#Compil").click(function() {
    var n_input = document.getElementById("designation").value;
    alert('Designation : ' + n_input); // -> n_input non defini (undefined)
});
<input id="designation" name="designation" type="text" size="12" />