`—` or `—` is there any difference in HTML output?

前端 未结 5 1446
孤城傲影
孤城傲影 2021-02-04 23:18

or

Is there a difference between these? Is one better-supported than the other?

5条回答
  •  被撕碎了的回忆
    2021-02-04 23:24

    :: :: \u2014

    When representing the m-dash in a JavaScript text string for output to HTML, note that it will be represented by its unicode value. There are cases when ampersand characters ('&') will not be resolved—notably certain contexts within JSX. In this case, neither nor will work. Instead you need to use the Unicode escape sequence: \u2014.

    For example, when implementing a render() method to output text from a JavaScript variable:

    render() {
       let text='JSX transcoders will preserve the & character—to ' 
                + 'protect from possible script hacking and cross-site hacks.'
       return (
         
    {text}
    ) }

    This will output:

    JSX transcoders will preserve the & character—to protect from possible script hacking and cross-site hacks.

    Instead of the &– prefixed representation, you should use \u2014:

    let text='JSX transcoders will preserve the & character\u2014to …'
    

提交回复
热议问题