Javascript
 Computer >> コンピューター >  >> プログラミング >> Javascript

JavaScriptを使用してWebページのpタグの配列のすべての値を表示します


これには、.data(anyArrayObject)を使用できます。以下はコードです-

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<script>
   const arrayValues = [1000000001,"John","Smith",100, 200, 3000]
   var originalData = d3.select("body").selectAll("p")
   .data(arrayValues)
   .enter()
   .append("p")
   .text(function(allValuesOfArray){
      console.log(allValuesOfArray+" ");
      return allValuesOfArray;
   })
</script>
</body>
</html>

上記のプログラムを実行するには、ファイル名anyName.html(index.html)を保存し、ファイルを右クリックして、VSCodeEditorで[ライブサーバーで開く]オプションを選択します。

出力

これにより、次の出力が生成されます-

JavaScriptを使用してWebページのpタグの配列のすべての値を表示します


  1. JavaScriptは関数の結果をHTMLとして表示しますか?

    関数の結果をHTMLとして表示するには、-を使用できます。 document.getElementById().innerHTML. 例 以下はコードです- <!DOCTYPE html> <html lang="en"> <head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0&

  2. Webページでビデオタグを非表示にする-JavaScript

    Webページに次のサンプルビデオタグがあるとします <video class="hideVideo" width="350" height="255" controls>    <source src="" id="unique_video_id">    You cannot play video here...... </video> Webページで動画を非表示にするには、yourVariableName.styl