Добавьте поддержку гиперссылок в скрипт QotD

#javascript #html

#язык JavaScript #HTML

Вопрос:

В скрипте, который я в настоящее время использую для «отображения котировок дня» при нажатии кнопки, отсутствует одна функция: поддержка ссылок=gt;, позволяющая нажимать на котировки, ведущие на веб-страницу.

Простое добавление обычной «ссылки» не работает, она просто отображается в виде текста.

Есть ли другой способ ?

 const arrayOfQuotes = [{  'quote': 'Every person that you meet knows something you do not learn from them - H Jackson'  },  {  'quote': 'Assume – to make an ASS out of U n ME Vermutung sei die Mutter des Untergangs'  },  {  'quote': 'Neither a borrower nor a lender be – Polonius Hamlet'  },  {  'quote': 'I am alive not my fault so I have to try and get by as best I can without hurting anybody - Leo Tolstoy'  },  {  'quote': 'There is always a chance – as long as one can – think – Basil of Bakerstreet'  },  {  'quote': 'Bleib dem treu was dich besonders macht dann folgt das Gute und Schöne im Leben hinterher'  },  {  'quote': 'There is no such thing as karma That only exists in a fair world and we both know the world is anything but fair'  },  {  'quote': 'Invention requires an excited mind Execution a calm one'  },  {  'quote': 'Ein Mensch ohne Phantasie ist wie ein Vogel ohne Flügel - Wilhelm Raabe'  },  {  'quote': 'As soon as you give up hope – everything is lost '  },  {  'quote': 'You are only truly alone if you choose to be alone'  },  {  'quote': 'Data!data!data! I cannnot make bricks without clay - ACDoyle'  },  {  'quote': 'Nothing ever goes away until it teaches us what we need to know - Perma Chodron'  },  {  'quote': 'We attract what we are'  },  {  'quote': 'The person who broke you cannot be the one to fix you'  },  {  'quote': 'There is only one way to avoid criticism Do nothing say nothing and be nothing – Aristotle'  },  {  'quote': 'I know nothing except the fact of my ignorance - Aristotle'  },  {  'quote': 'If you are absent during my struggle do not expect to be present during my success – Will Smith'  },  {  'quote': 'It's not Music - It's magic'  },  {  'quote': 'Sometimes - indeed - there is such a discrepancy between the genius and his human qualities that one has to ask oneself whether a little less talent might not have been better - C. G. Jung'  }, ];  function generateQuote() {  const random = Number.parseInt(Math.random() * arrayOfQuotes.length   1);  document.querySelector('#quoteOutput').textContent = `"${arrayOfQuotes[random].quote}"`; } 
 div {  text-align: left; }  h1 {  font-size: 11px;  font-family: Arial; }  button {  width: 128px;  height: 28px;  background-color: white;  color: black; }  {  font-size: 11px; }  button:hover {  background-color: white; }  lt;/stylegt;lt;/headgt;lt;bodygt; 
 lt;divgt;lt;button onclick="generateQuote();"gt;QuoteOfTheDaylt;/buttongt;  lt;p id="quoteOutput"gt; lt;/divgt; 

Комментарии:

1. Вместо textContent того, чтобы пытаться innerHTML . Кроме того, я не уверен, почему вы добавляете 1 в arrayOfQuotes.length 1

Ответ №1:

Как я уже говорил в своем комментарии выше, вместо textContent того, чтобы пытаться innerHTML . Кроме того, я не уверен, почему вы добавляете 1 в arrayOfQuotes.length 1

 const arrayOfQuotes = [{  'quote': 'lt;a href="#"gt;sample linklt;/agt; Every person that you meet knows something you do not learn from them - H Jackson'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Assume – to make an ASS out of U n ME Vermutung sei die Mutter des Untergangs'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Neither a borrower nor a lender be – Polonius Hamlet'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; I am alive not my fault so I have to try and get by as best I can without hurting anybody - Leo Tolstoy'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; There is always a chance – as long as one can – think – Basil of Bakerstreet'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Bleib dem treu was dich besonders macht dann folgt das Gute und Schöne im Leben hinterher'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; There is no such thing as karma That only exists in a fair world and we both know the world is anything but fair'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Invention requires an excited mind Execution a calm one'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Ein Mensch ohne Phantasie ist wie ein Vogel ohne Flügel - Wilhelm Raabe'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; As soon as you give up hope – everything is lost '  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; You are only truly alone if you choose to be alone'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Data!data!data! I cannnot make bricks without clay - ACDoyle'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Nothing ever goes away until it teaches us what we need to know - Perma Chodron'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; We attract what we are'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; The person who broke you cannot be the one to fix you'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; There is only one way to avoid criticism Do nothing say nothing and be nothing – Aristotle'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; I know nothing except the fact of my ignorance - Aristotle'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; If you are absent during my struggle do not expect to be present during my success – Will Smith'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; It's not Music - It's magic'  },  {  'quote': 'lt;a href="#"gt;sample linklt;/agt; Sometimes - indeed - there is such a discrepancy between the genius and his human qualities that one has to ask oneself whether a little less talent might not have been better - C. G. Jung'  }, ];  function generateQuote() {  const random = Number.parseInt(Math.random() * arrayOfQuotes.length);  document.querySelector('#quoteOutput').innerHTML = `"${arrayOfQuotes[random].quote}"`; } 
 div {  text-align: left; }  h1 {  font-size: 11px;  font-family: Arial; }  button {  width: 128px;  height: 28px;  background-color: white;  color: black; }  {  font-size: 11px; }  button:hover {  background-color: white; }  lt;/stylegt;lt;/headgt;lt;bodygt; 
 lt;divgt;lt;button onclick="generateQuote();"gt;QuoteOfTheDaylt;/buttongt;  lt;p id="quoteOutput"gt; lt;/divgt;