我有一个包含很多字符串的大数组 我想将其一一显示在文本字段中,并用空格键自动连接到每个文本字段
这里是我的代码
<script>
x=0
function abc(){
for (i=0;i<words[x].length;i++){
if(x=0)
x++;
document.getElementById("type").value=words[x];
}
</script>
我的输入字段 ID 是 type
,我的数组是 words
最佳答案
每次迭代都会将值设置为一个新单词,但不会添加到该值中。您可以用空格连接数组并将其设置为元素值:
document.getElementById("type").value = words.join(' ');
关于javascript - 如何在jquery的输入字段中用空格键逐一显示数组元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14562550/