Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript dom在HTML中插入Cite元素_Javascript - Fatal编程技术网

使用javascript dom在HTML中插入Cite元素

使用javascript dom在HTML中插入Cite元素,javascript,Javascript,我想在页脚标记中添加一个带有文本和href的cite元素,页脚标记存在于HTML中,但为空(当前) 我正在使用此代码,但它不起作用 let cite = document.createElement("cite"); cite.setAttribute("text","Information and photos from Wikipedia"); cite.setAttribute("href", "ht

我想在页脚标记中添加一个带有文本和href的cite元素,页脚标记存在于HTML中,但为空(当前)

我正在使用此代码,但它不起作用

let cite = document.createElement("cite");
cite.setAttribute("text","Information and photos from Wikipedia");
cite.setAttribute("href", "https://en.wikipedia.org/wiki/Bumblebee");
let ftr = document.getElementsByTagName('footer')[0];
ftr.innerHTML(cite);
我希望插入dom元素的HTML页面的代码是

<!DOCTYPE html>
<html lang="en">
<!-- DO NOT MODIFY THIS FILE OTHER THAN REFERENCING THE SCRIPT FILE -->

<head>
  <meta charset="UTF-8">
  <title>Assignment 5a</title>
  <link href="style.css" rel="stylesheet" />
</head>

<body>
  <header>
    <h1>Bumblebee</h1>
  </header>

  <main>
    <h2>General description</h2>

    <figure><img src="bee1.jpg" />
      <figcaption>A common bumblebee extending its tongue towards a Heuchera inflorescence.
      </figcaption>
    </figure>

    <p>Bumblebees  beast".</p>


    <h2>Distribution and habitat</h2>

    <figure><img src="bee2.jpg" />
      <figcaption>Cuckoo bumblebees have similar warning coloration to
        nest-making bumblebees.</figcaption>
    </figure>

    <p>Bumblebees t pollinators.</p>
  </main>
  <footer>

  </footer>
  <script type="text/javascript" src="script.js"></script>
</body>

</html>

任务5a
大黄蜂
一般说明
一种普通的大黄蜂,它的舌头伸向一个大黄蜂花序。
大黄蜂野兽”

分布和生境 布谷鸟大黄蜂的警告色与黄蜂相似 筑巢的大黄蜂。 大黄蜂不是传粉者

请注意,我不能在JS文件和文档中使用HTML标记。请写

您非常接近

本例使用
cite.textContent=
设置
cite
元素的内容,而不是设置名为“text”的属性


它还使用
ftr.appendChild(cite)
cite
元素添加到
ftr
footer元素。这是因为
innerHTML
不接受DOM元素,而是一个HTML字符串。因此
ftr.innerHTML='hello world
ftr.appendChild(cite)呢
相反?我正在尝试将cite元素添加到footer标记,类似于此文档。getElementsByTagName('footer')[0]。appendChild=cite;不,这不起作用。请尝试使用我的建议?ftr.appendChild(cite)不起作用