简体   繁体   English

如何在 p 标签中获取 output?

[英]How to get output in p tag?

Why this code doesn't get any outputs in p Tag?为什么这段代码在 p 标签中没有任何输出? Please explain it请解释一下

const inputName = document.getElementById("inputName");
const btnShow = document.getElementById("btnShow");
const pShow = document.getElementById("pShow");

btnShow.addEventListener("click", () => {
  const text = inputName.Value;
  pShow.textContent = text;
});
console.log(inputName, btnShow, pShow);

Input elements have value property and not Value , do it like this:输入元素具有value属性而不是Value ,这样做:

 const inputName = document.getElementById("inputName"); const btnShow = document.getElementById("btnShow"); const pShow = document.getElementById("pShow"); btnShow.addEventListener("click", () => { const text = inputName.value; pShow.textContent = text; });
 <input type="text" id="inputName"> <button id="btnShow">Click Me!</button> <p id="pShow"></p>

value is writing with low letters值是用小写字母书写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM