答案 0 :(得分:1)
这样的事情:
var element = document.querySelector('.blubb');
var stringToArray = element.innerHTML.split('');
var reveresedArray = stringToArray.reverse();
element.innerHTML = ''; // empty contents from .blubb
reveresedArray.forEach(function(letter){
element.innerHTML += '<p>' + letter + '</p>'; // add letter with <p> tag
});
<div class="blubb">Ineedtodisplay</div>
答案 1 :(得分:1)
function display() {
var i = 0;
var str="YourString";
var temp = str.split("");
var reversestr = temp.reverse();
for (var i = 0, len = reversestr .length; i < len; i++) {
document.write(reversestr [i] + "<br />");
}
};
<!DOCTYPE html>
<html>
<body>
<h2>My Vertical Display</h2>
<button type="button"
onclick="display()">
Click me to display.</button>
</body>
</html>
答案 2 :(得分:0)
从上到下书写,但先将其还原
document.write(str.split('').reverse().join('<br>'));
答案 3 :(得分:0)
<script>
var str = "ineedtodisplay";
document.getElementById('a').innerHTML = str.split('').join('<br/>');
</script>
答案 4 :(得分:0)
// reverse the element's string order
var elm = document.querySelector('p');
elm.textContent = elm.textContent.split("").reverse().join("");
&#13;
p{
font: 20px monospace; /* monospace fonts are best since each character has the same width */
width: 20px; /* same as font-size */
word-break: break-all; /* enabling the non-spaced text to break */
}
&#13;
<p>TEXT GOES FROM BOTTOM</p>
&#13;