textarea高亮react
时间: 2023-09-05 08:08:26 浏览: 172
文本匹配高亮
要在<textarea>中高亮React,你可以使用第一个引用中提到的react-highlight-within-textarea库。首先,你需要安装该库,可以使用npm install --save react-highlight-within-textarea命令进行安装。然后,你需要在代码中导入React和useState,以及react-highlight-within-textarea库。接下来,在<textarea>标签中使用highlight属性来启用高亮功能。最后,你可以在高亮函数中使用dangerouslySetInnerHTML来将匹配到的关键词用<span>标签包裹起来,从而实现高亮效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [react-highlight-within-textarea:React组件用于突出显示文本区域内的文本](https://download.csdn.net/download/weixin_42136837/18211252)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [react 搜索框高亮关键字 (函数封装)](https://blog.csdn.net/weixin_58515303/article/details/121892799)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文