当前位置: 首页 > 知识库问答 >
问题:

向QotD脚本添加超链接支持

殷轶
2023-03-14

我目前在按钮按钮上用于“显示当天报价”的脚本缺少一个功能:链接支持=

仅仅添加一个普通的“href”不起作用,它只显示为文本。

还有别的办法吗?

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;
}

</style></head><body>
<div><button onclick="generateQuote();">QuoteOfTheDay</button>
  <p id="quoteOutput">
</div>

共有1个答案

董胡非
2023-03-14

正如我在上面的评论中所说,尝试innerHTML而不是text Content。另外,我不知道为什么要在arrayOfQuotes.length1中添加1

const arrayOfQuotes = [{
    'quote': '<a href="#">sample link</a> Every person that you meet knows something you do not  learn from them - H Jackson'
  },
  {
    'quote': '<a href="#">sample link</a> Assume – to make an ASS out of U n ME  Vermutung sei die Mutter des Untergangs'
  },
  {
    'quote': '<a href="#">sample link</a> Neither a borrower nor a lender be – Polonius Hamlet'
  },
  {
    'quote': '<a href="#">sample link</a> I am alive not my fault so I have to try and get by as best I can without hurting anybody - Leo Tolstoy'
  },
  {
    'quote': '<a href="#">sample link</a> There is always a chance – as long as one can – think – Basil of Bakerstreet'
  },
  {
    'quote': '<a href="#">sample link</a> Bleib dem treu was dich besonders macht  dann folgt das Gute und Schöne im Leben hinterher'
  },
  {
    'quote': '<a href="#">sample link</a> 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': '<a href="#">sample link</a> Invention requires an excited mind Execution a calm one'
  },
  {
    'quote': '<a href="#">sample link</a> Ein Mensch ohne Phantasie ist wie ein Vogel ohne Flügel - Wilhelm Raabe'
  },
  {
    'quote': '<a href="#">sample link</a> As soon as you give up hope – everything is lost  '
  },
  {
    'quote': '<a href="#">sample link</a> You are only truly alone if you choose to be alone'
  },
  {
    'quote': '<a href="#">sample link</a> Data!data!data! I cannnot make bricks without clay  - ACDoyle'
  },
  {
    'quote': '<a href="#">sample link</a> Nothing ever goes away until it teaches us what we need to know - Perma Chodron'
  },
  {
    'quote': '<a href="#">sample link</a> We attract what we are'
  },
  {
    'quote': '<a href="#">sample link</a> The person who broke you cannot be the one to fix you'
  },
  {
    'quote': '<a href="#">sample link</a> There is only one way to avoid criticism   Do nothing say nothing  and be nothing – Aristotle'
  },
  {
    'quote': '<a href="#">sample link</a> I know nothing except the fact of my ignorance - Aristotle'
  },
  {
    'quote': '<a href="#">sample link</a> If you are absent during my struggle  do not expect to be present during my success – Will Smith'
  },
  {
    'quote': '<a href="#">sample link</a> It\'s not Music - It\'s magic'
  },
  {
    'quote': '<a href="#">sample link</a> 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;
}

</style></head><body>
<div><button onclick="generateQuote();">QuoteOfTheDay</button>
  <p id="quoteOutput">
</div>
 类似资料:
  • 我正在开发一个页面,该页面使用JavaScipt通过ajaxpost将数据发送到PHP脚本。问题是,如果输入的语言不是基于拉丁语的,我最终会在MySQL表中存储胡言乱语。拉丁字母很好用。 页面本身能够呈现UTF-8字符,如果这些字符在页面加载时提供的数据中,那么我要处理的就是这篇文章。 اختبار 和保存。请参阅浏览器的开发工具中的网络POST请求。 这篇文章是通过下面的JS函数完成的 这是我的

  • 有什么想法如何添加一个超链接在一个网页上使用这个库? 我发现了这个问题:如何使用pdfbox在内容中设置超链接,但这不起作用。 我只想在pdf文件的第一页添加一个超链接。 我更喜欢在页面底部添加以URL为中心的超链接。但目前任何建议都有帮助

  • 我正在用apache poi xslf库创建一个Powerpoint演示文稿。我需要创建一个自动形状,当单击自动形状时,它应该转到特定的幻灯片。 我可以通过向自动形状添加文本并创建如下所示的超链接来做到这一点。 但问题是,当我创建这样一个自动形状时,它实际上链接文本而不是形状。此外,当我从Powerpoint打开它时,它会以蓝色下划线的文本显示超链接,我不想这样做。 在Powerpoint中,您可

  • 我有一个比较简单的问题,就是尝试将内联脚本添加到React组件中。我目前所掌握的: 我还尝试过: 这两种方法似乎都无法执行所需的脚本。我想我错过的是一件简单的事。有人能帮忙吗? PS:忽略foobar,我有一个真实的id实际上在使用,我不想分享。

  • 我使用Microsoft Excel2007。我在第一个excel表上有一个简单的形状。我想在这个简单的形状上添加一个超链接,它引用了特定行和列上的另一个工作表。我对此进行了研究,但我只找到了演示如何向给定单元格添加超链接的示例。如何在Apache POI的帮助下向给定的简单形状添加超链接?

  • 问题内容: 是否有人知道一个脚本,该脚本可以选择对URL的所有文本引用,并自动将其替换为指向这些位置的锚标记? 注意:我想要这个是因为我不想浏览所有内容,并用锚标记将它们包装起来。 问题答案: 对我来说,这似乎是jQuery的完美任务。 …这样的事情浮现在我脑海: