Javascript 如何在ReactJS中为锚定标记的title属性呈现带引号标记的字符串
考虑以下代码:Javascript 如何在ReactJS中为锚定标记的title属性呈现带引号标记的字符串,javascript,reactjs,Javascript,Reactjs,考虑以下代码: const dataObj = { 'title': 'Who is the author of the book ‘A Brief History of Time’?', 'link': 'https://mcqacademy.com/read-more-slug/', 'htmlMarkup': '<p>more html markup goes here</p>', }; return
const dataObj = {
'title': 'Who is the author of the book ‘A Brief History of Time’?',
'link': 'https://mcqacademy.com/read-more-slug/',
'htmlMarkup': '<p>more html markup goes here</p>',
};
return (
<a href={dataObj.link}
className="read-more-link"
title={dataObj.title}
dangerouslySetInnerHTML={{__html: dataObj.htmlMarkup}}></a>
);
标题中的标记不会呈现!如何添加title属性以正确显示?因为
title
是字符串,而不是HTML。将其添加为HTML时,必须使用标记,如下所示:
<title>HTML content so ‘markup’ me</title>
HTML内容so‘;标记&8217;我
在字符串属性中,您可以添加任意数量的字符,而无需对其进行编码,因为浏览器知道要呈现的不是HTML,而是字符串:
<element title="this is my string with <weird> characters,'single' and \"double\" quotes"/>
编辑:要使此答案更清楚,只需将对象更改为:
const dataObj = {
'title': 'Who is the author of the book \'A Brief History of Time\'?',
'link': 'https://mcqacademy.com/read-more-slug/',
'htmlMarkup': '<p>more html markup goes here</p>',
};
const dataObj={
“标题”:谁是《时间简史》一书的作者,
“链接”:https://mcqacademy.com/read-more-slug/',
“htmlMarkup”:“这里有更多的html标记”,
};
这是有道理的,请看dataObj.title
我需要在title属性中呈现dataObj.title
。嗨,我的回答对你有帮助吗?你的问题中被接受的答案比例真的很糟糕。那太自私了。至少向那些试图免费帮助你的人反馈一些东西。我需要使用title属性,而不是作为单独的html标记。请再次检查该问题。@ShahAlom谁说要将其用作单独的标签?请仔细阅读我的答案。第一段代码只是一个必须使用标记的示例。
const dataObj = {
'title': 'Who is the author of the book \'A Brief History of Time\'?',
'link': 'https://mcqacademy.com/read-more-slug/',
'htmlMarkup': '<p>more html markup goes here</p>',
};