Js无法读取输入的.value属性。为什么? [英] Js can't read the .value property for an input. Why?
本文介绍了Js无法读取输入的.value属性。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有来自html文件的输入。
我有一个js文件。
但是当我点击提交时按钮,有一个错误。为什么?
代码:
html:
i have an input from html file.
and i have an js file.
but when i hit the "Submit" button, there's a error. why?
the code:
html:
<form method="" action="">
<input autofocus type="text" name="mission" id="mission" class="" placeholder="" required >
<label id="" for="mission"> name: </label>
<button id="submit" type="submit">submit</button>
</form>
js:
js:
var button = document.querySelector("#submit");
button.addEventListener("click", function(){
var firstAns = document.getElementById("#mission").value;
console.log(firstAns); //there's an error
});
我尝试过:
阅读一些文章,但我什么都没有。
What I have tried:
read some articles but i have got nothing.
推荐答案
只需输入任务
而不是#mission
。 getElementById不需要#。
Just putmission
instead of#mission
. getElementById does not want the #.
这篇关于Js无法读取输入的.value属性。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文