问题
I have an array of objects and within each object there is an answers section, but I need to hyperlink some certain words that should send the user to a website.
I have given an example below.
faq: [
{
answers: "The capital is London"
}
]
So in the example above if you could show me how I can hyperlink the word London within Javascript it would be very helpful.
Many thanks!
回答1:
Just surround the word with anchor tag . Like this and give url after //
<a href="//www.google.com">London</a>
回答2:
Try this one. You can put your link instead of https://www.google.com. This will create hyperlink for word 'London'
<script>
function myFunction() {
var result = "The capital is" + "London".link("https://www.google.com");
document.getElementById("demo").innerHTML = result;
}
</script>
来源:https://stackoverflow.com/questions/53812940/adding-hyperlink-in-javascript-array-of-objects