I really want to know how to do this, instead of "james".length
to show in the console, how do I make it show on the webpage? Like having the number 5 showing on the page instead of the console.
这会将其放入id="somediv"
的DIV中:
document.getElementById("somediv").innerText = "james".length;
这样尝试
document.body.innerHTML = "james".length;
Say you have a div with id outputDiv
.
You can print to this div by doing:
var outputDiv = document.getElementById('outputDiv');
outputDiv.innerHTML += "james".length;
If you want to add individual paragraphs one at a time you can do:
var p = document.createElement('p');
p.innerHTML = "james".length;
outputDiv.appendChild(p);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.