把一個字符串里符合表情文字標簽的地方全部替換為相應的圖片的方法

1、表情數據:

var emotion =[{"name": "Expression_1","text": "[微笑]"},{"name": "Expression_2","text": "[撇嘴]"},{"name": "Expression_3","text": "[色]"},{"name": "Expression_4","text": "[發呆]"},{"name": "Expression_5","text": "[得意]"},{"name": "Expression_6","text": "[流淚]"},{"name": "Expression_7","text": "[害羞]"},{"name": "Expression_8","text": "[閉嘴]"},{"name": "Expression_9","text": "[睡]"},{"name": "Expression_10","text": "[大哭]"},{"name": "Expression_11","text": "[尷尬]"},{"name": "Expression_12","text": "[發怒]"},{"name": "Expression_13","text": "[調皮]"},{"name": "Expression_14","text": "[呲牙]"},{"name": "Expression_15","text": "[驚訝]"},{"name": "Expression_16","text": "[難過]"},{"name": "Expression_17","text": "[酷]"},{"name": "Expression_18","text": "[冷汗]"},{"name": "Expression_19","text": "[抓狂]"},{"name": "Expression_20","text": "[吐]"},{"name": "Expression_21","text": "[偷笑]"},{"name": "Expression_22","text": "[愉快]"},{"name": "Expression_23","text": "[白眼]"},{"name": "Expression_24","text": "[傲慢]"},{"name": "Expression_25","text": "[饑餓]"},{"name": "Expression_26","text": "[困]"},{"name": "Expression_27","text": "[恐懼]"},{"name": "Expression_28","text": "[流汗]"},{"name": "Expression_29","text": "[憨笑]"},{"name": "Expression_30","text": "[悠閑]"},{"name": "Expression_31","text": "[奮斗]"},{"name": "Expression_32","text": "[咒罵]"},{"name": "Expression_33","text": "[疑問]"},{"name": "Expression_34","text": "[噓]"},{"name": "Expression_35","text": "[暈]"},{"name": "Expression_36","text": "[瘋了]"},{"name": "Expression_37","text": "[衰]"},{"name": "Expression_38","text": "[骷髏]"},{"name": "Expression_39","text": "[敲打]"},{"name": "Expression_40","text": "[再見]"},{"name": "Expression_41","text": "[擦汗]"},{"name": "Expression_42","text": "[摳鼻]"},{"name": "Expression_43","text": "[鼓掌]"},{"name": "Expression_44","text": "[糗大了]"},{"name": "Expression_45","text": "[壞笑]"},{"name": "Expression_46","text": "[左哼哼]"},{"name": "Expression_47","text": "[右哼哼]"},{"name": "Expression_48","text": "[哈欠]"},{"name": "Expression_49","text": "[鄙視]"},{"name": "Expression_50","text": "[委屈]"},{"name": "Expression_51","text": "[快哭了]"},{"name": "Expression_52","text": "[陰險]"},{"name": "Expression_53","text": "[親親]"},{"name": "Expression_54","text": "[嚇]"},{"name": "Expression_55","text": "[可憐]"},{"name": "Expression_56","text": "[菜刀]"},{"name": "Expression_57","text": "[西瓜]"},{"name": "Expression_58","text": "[啤酒]"},{"name": "Expression_59","text": "[籃球]"},{"name": "Expression_60","text": "[乒乓]"},{"name": "Expression_61","text": "[咖啡]"},{"name": "Expression_62","text": "[飯]"},{"name": "Expression_63","text": "[豬頭]"},{"name": "Expression_64","text": "[玫瑰]"},{"name": "Expression_65","text": "[凋謝]"},{"name": "Expression_66","text": "[嘴唇]"},{"name": "Expression_67","text": "[愛心]"},{"name": "Expression_68","text": "[心碎]"},{"name": "Expression_69","text": "[蛋糕]"},{"name": "Expression_70","text": "[閃電]"},{"name": "Expression_71","text": "[炸彈]"},{"name": "Expression_72","text": "[刀]"},{"name": "Expression_73","text": "[足球]"},{"name": "Expression_74","text": "[瓢蟲]"},{"name": "Expression_75","text": "[便便]"},{"name": "Expression_76","text": "[月亮]"},{"name": "Expression_77","text": "[太陽]"},{"name": "Expression_78","text": "[禮物]"},{"name": "Expression_79","text": "[擁抱]"},{"name": "Expression_80","text": "[強]"},{"name": "Expression_81","text": "[弱]"},{"name": "Expression_82","text": "[握手]"},{"name": "Expression_83","text": "[勝利]"},{"name": "Expression_84","text": "[抱拳]"},{"name": "Expression_85","text": "[勾引]"},{"name": "Expression_86","text": "[拳頭]"},{"name": "Expression_87","text": "[差勁]"},{"name": "Expression_88","text": "[愛你]"},{"name": "Expression_89","text": "[NO]"},{"name": "Expression_90","text": "[OK]"},{"name": "Expression_91","text": "[愛情]"},{"name": "Expression_92","text": "[飛吻]"},{"name": "Expression_93","text": "[跳跳]"},{"name": "Expression_94","text": "[發抖]"},{"name": "Expression_95","text": "[慪火]"},{"name": "Expression_96","text": "[轉圈]"},{"name": "Expression_97","text": "[磕頭]"},{"name": "Expression_98","text": "[回頭]"},{"name": "Expression_99","text": "[跳繩]"},{"name": "Expression_100","text": "[投降]"},{"name": "Expression_101","text": "[激動]"},{"name": "Expression_102","text": "[街舞]"},{"name": "Expression_103","text": "[獻吻]"},{"name": "Expression_104","text": "[左太極]"},{"name": "Expression_105","text": "[右太極]"}]

2、有一個字符串strCont="[微笑]不要說人家啦![撇嘴]人家好[害羞]啊"

3、批量替換方法:

/批量替換方法
function ReCont(strCont) {for (var i in emotion) {        var item = emotion[i];var strimg='<img src="../image/emotion/'+item.name+'.png" width="24" height="24" align="absmiddle">';var reg=new RegExp("\\"+item.text,"g");//alert(reg);strCont=strCont.replace(reg, strimg);//alert(strCont);
    }    return strCont;
}

然后使用:newContent=ReCont(strCont)就可以把表情標簽更換為圖片了。

另插入小說明:在js里插入特殊字符:

下面的表格列出了其余的特殊字符,這些特殊字符都可以使用反斜杠來添加到文本字符串中:代碼 輸出\’ 單引號\" 雙引號

\& 和號\\ 反斜杠\n 換行符\r 回車符\t 制表符\b 退格符

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/284552.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/284552.shtml
英文地址,請注明出處:http://en.pswp.cn/news/284552.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【ArcGIS微課1000例】0029:ArcGIS繪制平行線(構造平行公路)

在實際工作中,有時需要繪制平行線,比如道路兩邊的邊界線,可以使用“平行復制”功能快速繪制平行線,本文介紹如何使用“平行復制”功能快速繪制平行線。 1. 加載公路矢量 加載配套實驗數據包中的數據0029.rar中的矢量數據:公路。 2. 生成平行公路 點擊“編輯器”→“開始…

2017年初隨想——幾個小目標

回顧往事很慘&#xff0c;展望未來渺茫 2016年不順的事情一籮筐&#xff0c;母親追求信仰&#xff08;誤入歧途&#xff09;導致父母離婚&#xff0c;父親又遭遇車禍&#xff0c;現在依然癱瘓在床&#xff0c;意識都尚未清醒&#xff0c;母親卻依然杳無音信。而我則剛工作2年半…

Win11 沒有磁盤清理工具,如何清理磁盤舊的windows.old文件

win11 磁盤右鍵沒有了“磁盤清理工具” 如果想清理文件&#xff0c;可以打開設置&#xff08;WinI&#xff09;系統—存儲—清理建議 您也可以打開“存儲感知”&#xff0c;系統會在需要時幫你自動清理文件。

腳本進階,函數調用實例練習

一、練習&#xff1a;腳本&#xff1a;判定192.168.0.200-192.168.0.254之間哪些主機在線&#xff0c;要求&#xff1a;1、使用函數來實現一臺主機的判定過程&#xff1a;2、在主程序中調用此函數判定指定范圍內的所有主機的在線情況&#xff0c;vim ping.sh#!/bin/bash#PING()…

.NET開發云原生應用,你只差給自己加個油

為什么要云原生&#xff08;Cloud Native&#xff09;Cloud表示應用程序位于云中&#xff0c;而不是傳統的數據中心&#xff1b;Native表示應用程序從設計之初即考慮到云的環境&#xff0c;原生為云而設計&#xff0c;在云上以最佳姿勢運行&#xff0c;充分利用和發揮云平臺的彈…

java成員變量的初始化

2019獨角獸企業重金招聘Python工程師標準>>> 類變量(static變量,不需要實例化對象也可以引用) 實例變量(非static變量,需要實例化對象) 局部變量(類的成員函數中的變量) 初始化方式: 構造函數初始化 變量聲明時初始化 代碼塊初始化 java自動初始化(在構造函數執行之…

Win11 的日歷 替代

Win11 的日歷雖然漂亮&#xff0c;卻少了很多小功能&#xff0c;特別是沒有秒鐘和日程的設計&#xff0c;讓用慣了 Win10 的小伙伴大呼不滿。原來曾經用過360帶的日歷&#xff0c;可惜不支持Win11&#xff0c;下面這個日歷是一款功能強大、顏值很高的小工具&#xff0c;能夠提供…

ReactNative--React簡介

React 基礎框架&#xff0c;是一些實現理念&#xff0c;不能用來做網頁的開發和手機應用的開發 React.js 用來做網頁開發 ReactNative 移動應用開發 在學習ReactNative之前&#xff0c;先學習React http://reactnative.cn/ 中文網 http://facebook.github.io/react-nativ…

【ArcGIS微課1000例】0030:ArcGIS利用MXD doctor工具分析并修復mxd地圖文檔

MXD Doctor 是一個獨立的應用程序,位于 ArcGIS Desktop 安裝目錄下的 Tools 文件夾中。該工具可用于分析已損壞的 .mxd 文件。根據分析結果,可將已損壞的 .mxd 文件中所包含的實體復制到新的或現有 .mxd 文件中。 可以從所有程序 > ArcGIS > Desktop 工具中打開 MXD Do…

分析一個 .NET 寫的 某 RFID標簽系統 CPU暴漲

一&#xff1a;背景 1. 講故事前段時間有位朋友說他的程序 CPU 出現了暴漲現象&#xff0c;由于程序是買來的&#xff0c;所以問題就比較棘手了&#xff0c;那既然找到我&#xff0c;就想辦法幫朋友找出來吧&#xff0c;分析下來&#xff0c;問題比較經典&#xff0c;有必要和大…

linux開機引導過程總覽

簡單的說&#xff0c;系統的啟動過程如下&#xff1a; 1.開機自檢&#xff1a; 按下電源按鍵后&#xff0c;計算機硬件會主動讀取BIOS加載硬件信息并進行硬件的自我測試&#xff0c;然后系統會根據BIOS里的啟動順序讀取第一個可啟動的設備&#xff0c;從而移交系統控制權&#…

CentOS關機與重啟命令詳解

2019獨角獸企業重金招聘Python工程師標準>>> Linux centos重啟命令&#xff1a; 1、reboot  2、shutdown -r now 立刻重啟(root用戶使用)  3、shutdown -r 10 過10分鐘自動重啟(root用戶使用)  4、shutdown -r 20:35 在時間為20:35時候重啟(root用戶使用)如果…

JS正則提取字符串

河北科技師范學院歐美學院新聞標題 河南大學邁阿密學院新聞標題 首都經濟貿易大學密云分校新聞標題 北京科技大學(延慶校區)新聞標題 湖北中醫藥大學職業技術學院新聞標題 公安消防部隊高等專科學校新聞標題 從上邊的類似新聞標題中提取完整學校名稱&#xff0c;最終參考代…

【工具】PC端調試手機端 Html 頁面的工具

一、概述 有一個項目需要在手機端顯示一個 web 頁面&#xff0c;而每次把應用 launch 后&#xff0c;從手機端看比較麻煩&#xff0c;因此搜羅了幾種在 PC 端調試手機端頁面的工具。 二、工具 http://fonkie.iteye.com/blog/1846858 http://blog.csdn.net/dojotoolkit/article/…

【ArcGIS微課1000例】0031:ArcGIS中的32個拓撲規則(圖文詳解)

在地理數據庫中,拓撲是定義點要素、線要素以及面要素共享重疊幾何的方式的排列布置。例如,街道中心線與人口普查區塊共享公共幾何,相鄰的土壤面共享公共邊界。學習拓撲就必須掌握ArcGIS中常見的拓撲規則。 文章目錄 一、面的拓撲規則(10種)二、點的拓撲規則(6種)三、線的…

Blazor University (38)JavaScript 互操作 —— 從 .NET 調用 JavaScript

原文鏈接&#xff1a;https://blazor-university.com/javascript-interop/calling-javascript-from-dotnet/從 .NET 調用 JavaScriptJavaScript 應添加到服務器端 Blazor 應用程序的 /Pages/_Host.cshtml 或 Web Assembly Blazor 應用程序的 wwwroot/index.html 中。然后可以通…

十大排序總結(js實現、穩定性、內外部排序區別、時間空間復雜度、冒泡、快速、直接選擇、堆、直接插入、希爾、桶、基數、歸并、計數排序)

目錄 排序相關概念 穩定性 內部排序 外部排序 十種排序算法特點總結 交換排序 冒泡排序&#xff08;數組sort方法的原理&#xff09; 圖解 js實現 特點 快速排序 圖解 js實現 特點 選擇排序 直接選擇排序 圖解 js實現 特點 堆排序 大&#xff08;小&#xff0…

三維重建技術概述

基于視覺的三維重建&#xff0c;指的是通過攝像機獲取場景物體的數據圖像&#xff0c;并對此圖像進行分析處理&#xff0c;再結合計算機視覺知識推導出現實環境中物體的三維信息。 1. 相關概念 &#xff08;1&#xff09;彩色圖像與深度圖像 彩色圖像也叫作RGB圖像&#xff0c;…

【ArcGIS微課1000例】0032:ArcGIS中河流(曲線)、湖泊(水體色)圖例制作案例教程

河流作為線要素,在符號化的過程中使用的大多都是直線符號,但是為了能夠在出圖的使用表現形象的河流對象,就有了使用曲線表示河流圖例的需求,湖泊亦是如此。本文講解在ArcGIS中制作標準的河流和湖泊圖例的完整教程。 文章目錄 一、案例效果二、圖例制作三、圖例修改一、案例…

從shiro源碼角度學習工廠方法設計模式

緒論 shiro是一個簡單易用&#xff0c;功能強大的Java安全框架&#xff0c;學習其源碼設計思想對我們的編碼水平的提高大有裨益。現在&#xff0c;就從源碼角度帶大家學習一下shiro里面的工廠方法模式。 這里的前提是讀者有過使用shiro的基礎&#xff0c;沒有也行&#xff0c;關…