我该如何在旅途中添加一些段落,并将结果显示在带有段落标记的文档中

how would i go about adding some paragraphs on the go and show the result to the document with paragraph tags

本文关键字:显示 结果 文档 段落标 旅途 途中 添加 段落      更新时间:2023-09-26

我需要直接从打印的脚本中添加3个段落标记与控制台上登录的内容相同

<script >
var array= [1,2,4];
  $.each(array,function (index,value)   {
     console.log(index + ": "+value)
    });
</script>

在此处使用此演示

 <script>
    var array= [1,2,4];
  $.each(array,function (index,value)   {
       $('<p>').appendTo('body').html(index + ": "+value);
  })
    </script>

也许它会对您有所帮助。

var array= [1,2,4];
  $.each(array,function(index,value){
     $('<p />').appendTo('#apd').html(index + ": "+value);
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id='apd'></div>

试试这个。。

<body>
<div id="data"></div>
</body>
<script>
var test="";
var array= [1,2,4];
 for (i = 0; i < array.length; i++) { 
      test += '<p>'+i+ ':'+array[i]+'</p>';
    }
    document.getElementById("data").innerHTML = test;
</script>

输出:

0:1
1:2
2:4