简体   繁体   中英

Javascript - passing anchor into a span from .innerHTML

I have an external js file, wanting to put a link into a span on the html file.

   function QuizDetails() {

    document.getElementById("quiz-link").innerHTML = <a href="quiz.html">Take quiz again</a>;

 }

The html code

<p><span id="quiz-link"></span></p>

For some reason the js dosent run, the code below works fine but obvious I want to pass an anchor. Any ideas?

   function QuizDetails() {

document.getElementById("quiz-link").innerHTML = "take quiz again";

}

您缺少引号...

  document.getElementById("quiz-link").innerHTML = '<a href="quiz.html">Take quiz again</a>'; 
 <p><span id="quiz-link"></span></p> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM