ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## escape + [link](./escape "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L12160 "View in source.") + [npm](https://www.npmjs.com/package/lodash.escape "See the npm package.") ``` _.escape([string='']) ``` 转义字符 "&", "<", ">", '"', "'", 以及 "`" 为HTML实体字符。 **注意:** 不会转义其他字符,如果需要,可以使用第三方库,例如 [_he_](https://mths.be/he)。 虽然 ">" 是对称转义的,像是 ">" 和 "/" 没有特殊的意义,所以不需要在 HTML 中转义。 除非它们是标签的一部分,或者是不带引号的属性值。 查看 [Mathias Bynens 的文章](https://mathiasbynens.be/notes/ambiguous-ampersands) (under "semi-related fun fact") 了解详情 在 IE < 9 中转义引号,因为会中断属性值或 HTML 注释,查看 [HTML5 安全列表](https://html5sec.org/) 的 [#59](https://html5sec.org/#59), [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), 以及 [#133](https://html5sec.org/#133) 了解详情 当解析为 HTML 时应该总是 [引用属性值](http://wonko.com/post/html-escaping) 以减少 XSS 的可能性。 ### 参数 1. [string=''] (string) 要转义的字符串 ### 返回值 (string) 返回转义后的字符串 ### 示例 ``` _.escape('fred, barney, & pebbles'); // => 'fred, barney, & pebbles' ```