[英]using string split method to split prompt values
I am trying to split my prompt values so that each word appears on a different line, but my code makes it so that the words are split by commas instead of to each line like I want it to. 我试图拆分我的提示值,以便每个单词出现在不同的行上,但是我的代码使得单词用逗号分隔,而不是像我想要的那样分成每一行。 Thank you so much for helping!
非常感谢您的帮助!
<p div id="a"></div></p>
<script>
window.onload=function() {
var x=prompt("Enter Terms", "Terms")
document.getElementById("a").innerHTML=x.split(" ");
for(var i=0; i < a.length; i++){
document.write(a[i]);
}
</script>
Use Array.prototype.join()
, joins all elements of an array
into a string
using specified argument
使用
Array.prototype.join()
, 使用指定的argument
将array
所有元素连接成一个string
window.onload = function() { var x = prompt("Enter Terms", "Terms"); document.getElementById("a").innerHTML = x.split(" ").join('<br/>'); }
<div id="a"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.