问题
I have created a post in Django. When a user types text and hits submit it shows in the page. Now I want to turn any hashtags in the text in to links. For example if a user types #sometext
it will show a link in the HTML replacing #sometext
. I was working on this and i got an error:
Uncaught SyntaxError: Unexpected token ','
$(document).ready(function() {
$('.reply-btn').click(function() {
$(this).parent().parent().next('.replied-comments').fadeToggle()
});
});
$(document).ready(function() {
function updateHashLinks() {
$("p").each(function(data) {
var hashtagRegex = /(^|\s)#([\w\d-]+)/g
var newText = $(this).html().replace(hashtagRegex, "$1<a href='/tags/$2/'>#$2</a>")
$(this).html(newText)
});
},
});
来源:https://stackoverflow.com/questions/60071985/how-to-replace-text-with-a-link