【发布时间】:2020-03-16 04:25:49
【问题描述】:
为什么console.log 语句返回undefined?
即使 标签 的 id 是 right 所以它应该返回存储在 <p> 标签中的值?
x=document.getElementById("pppp").value //assigning the value of <p> tag to x
console.log(x) //printing the value of x in console
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>blabla</title>
</head>
<body>
<p id="pppp">dvshjb</p>
</body>
</html>
【问题讨论】:
-
只有
input类型的元素有value..div不是其中之一 -
因为没有
p标签的值...而不是使用.value使用.textContent来获取dvshjb
标签: javascript html error-handling syntax-error