在React JSX中,我如何才能让以下文字包含单引号?还是其他可能需要转义的标点符号?
return (
<div>
<p>I've seen the movie.</p>
</div>
)
答案 0 :(得分:46)
$date = new DateTime( '-60 days' );
echo $date->format( 'Y-m-d H:i:s' );
答案 1 :(得分:11)
没关系,它按原样运作。
这是IDE将其强调为错误
答案 2 :(得分:2)
您可以使用html实体在文本中加引号。
<Text>I"ve seen the movie.</Text>
输出:我看过电影。
或如果要单引号,请使用以下选项:
<Text> I've seen the movie.</Text> <Text>{'I\'ve seen the movie.'}</Text> {/* you can use both ticks and single quotes depending on your use. */} <Text>{`I've seen the movie.`}</Text>
输出:我看过电影。
答案 3 :(得分:0)
这是在有意义的字符串上使用反引号(`
)的重要原因。
即使关闭了语法高亮显示,原始问题中的文本也可以正常工作,但是通过将字符串移动到一个常量,您可以避免担心转义,高亮显示,并且更容易查找/更新。
const TEXT_FOR_MOVIE = `Some text that's "quoted"`
const TEXT_FOR_MOVIE = Some text that's "quoted"