Article From:https://www.cnblogs.com/cowboybusy/p/9064471.html

First, let me first talk about the difference between innerHTML, innerText and value.

innerHTML Adding HTML code to the control is to set up HTML in an element.

eg:

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Insert title here</title>
</head>
<body>
<h1>My First Web Page</h1>
<p id=”demo”>My First Paragraph.</p>
<script>
document.getElementById(“demo”).innerHTML=”<h1>My First JavaScript</h1>”;
</script>
</body>
</html>

innerText Add text to a control

<html>
<body>
<h1>My First Web Page</h1>
<p id=”demo”>My First Paragraph.</p>
<script>
document.getElementById(“demo”).innerText=”<h1>My First JavaScript</h1>”;
</script>
</body>
</html>

value=”” What I understand is that the value attribute in the control is directly assigned to something in double quotes.

[html] view plain copy
<html>
<body>
<h1>My First Web Page</h1>
<p id=”demo”>My First Paragraph.</p>
<input id=”input” type=”text”></input>
<script>
document.getElementById(“input”).value=”<h1>My First JavaScript</h1>”;
</script>
</body>
</html>

 

 

For example, < input/> value attribute shows content when < input value= “content” /> not < input > content < input />

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *