荣耀彩票代理

IT技术互动交流平台

如何简单操作写出HTML高亮关键字代码

作者:whl  发布日期:2018-11-13 08:32:00

荣耀彩票代理  HENDUORENDOUBIAOSHIZAIXIEDAIMADESHIHOUDOUYIWEIZHIXUYAOSHIYONGinnerHTML replaceJIUNENGJINXINGJIANDANDECAOZUO,DANZAIJINXINGSHIJICAOZUODESHIHOUQUEFAXIANZIJIXIANGDETAIJIANDANLE,YINCIZOULEBUSHAODEWANLU,PENGDAOBUSHAODEWENTI。XIAOBIANZHENGLILEYIXIEBIJIAOJUYOUJIAZHIDEWENTIHENENGGOUJIEJUEDEBANFA。

  CHANGYONGZUOFA:ZHENGZETIHUAN

  SILU:YAOXIANGGAOLIANGYUANSU,NEIMEXUYAOJIANGGUANJIANZITIQUCHULAIYONGBIAOQIANBAOGUO,RANHOUDUIBIAOQIANJINXINGYANGSHIDIAOZHENG。SHIYONG innerHTML,HUO outHTML, ERBUNENGSHIYONG innerText,outText。

荣耀彩票代理  ZHEIYANGZUOCUNZAIDEYINHUANYOURUXIA:

  keyword荣耀彩票代理 如果是 ()\ 等正则对象的关键字将会构建正则对象失败。(可以通过转义解决)

  keyword 如果是一些 HTML 标签如 div 将会对 innerHTML 进行错误的替换

荣耀彩票代理  keyword RUGUOHEYIXIEDOMSHUXINGMING、ZHIXIANGTONG,YEHUIDAOZHIYICHANGTIHUAN。RUXIADANG keyword WEI test SHI,HUIJIANG class MINGYECUOWUDETIHUANDIAO:

荣耀彩票代理  GUANJIANZIFUJIEDIAN element TONGGUO class LAIJINXINGBEIJINGRANSECHULI,DUIYUANSHIDOMYOUYIDINGCHENGDUWURAN,KENENGDUI element ZAICIDINGWEIZAOCHENGYINGXIANG。(ZUOWEICHAJIANXIWANGJINKENENGSHAOGAIBIANYUANSHIDOM)

荣耀彩票代理  ZHENGZEYOUHUAYI:JINCHULIWEIYUBIAOQIANNEIDEYUANSU

荣耀彩票代理  YINENGJIEJUEDADUOSHUWENTI,DANYIJIUCUNZAIDEWENTISHI,ZHIYAOBIAOQIANSHUXINGCUNZAILEISI < FUHAO,JIANGHUIDAPOPIPEIGUIZEDAOZHIZHENGZETIQUNEIRONGCUOWU, HTML5 dataset KEYIZIDINGYIRENYINEIRONG,GUZHEIXIETESHUZIFUSHIWUFABIMIANDE。

  ZHENGZEYOUHUAER:QINGCHUKENENGYINGXIANGDEBIAOQIAN

  ZHEIZHONGSILUJIYUANMACONGZHEILILAI, DANCUNZAIWENTISHI:

荣耀彩票代理  RUGUO [replaced1] BAOHAN keyword, NEIMETIHUANSHIJIANGFASHENGYICHANG

  ZUIZHONGYAODE,DANGBIAOQIANZHIZHONGBAOHAN <> FUHAOSHI,CIFANGFAYEBUNENGZHENGQUEDETIQUBIAOQIAN

  ZONGZHIZAIJINGGUOLENDUOCHANGSHIZHIHOU,TONGGUOZHENGZEDOUMEINENGYOUXIAODECHULIGEZHONGQINGKUANG。RANHOUHUANLEGESILU,BUTONGGUOZIFUCHUANDEFANGSHI,TONGGUOJIEDIANCHULI。element.childNodes KEYIZUIYOUXIAODEQINGLIBIAOQIANNEIDEGANRAOXINXI。

荣耀彩票代理  [WANMEIJIEJUEFANGAN]TONGGUO DOM JIEDIANCHULI

  通过 parent.childNodes 得到所有子节点。child 节点可以通过 innerText.replce(keyword,result) 的方式替换得到想要的高亮效果,如下: keyword 2荣耀彩票代理 (递归处理:当child节点不含子节点时进行replace操作)。

荣耀彩票代理  DANSHI keyword 1 SHISHUYUWENBENJIEDIAN,ZHINENGXIUGAIWENBENNEIRONG,WUFAZENGJIA HTML,GENGWUFADANDUKONGZHIQIYANGSHI。ERWENBENJIEDIANYEBUNENGZHUANHUANWEIPUTONGJIEDIAN,ZHEIYESHIZUIKUNAODESHIQING。

荣耀彩票代理  ZUIHOU~,BENWENDEZHONGDIANLAILE,YINWEIZHEIGEGONGNENG,RANGWODIYICIRENZHENJIECHUDAOLEWENBENJIEDIANZHEIGEDONGXI。CONGZHEILIFAXIANLEText,SHIYONGQIEGEWENBENJIEDIANBINGTIHUANDEFANGSHISHIXIANGAOLIANG。

荣耀彩票代理  YUANMAYIJIHAIYUANGAOLIANGJIANYUANMA

高亮见源码

荣耀彩票代理  ZUIHOU,LIUGECAIDAN,YISHANGFANGFAYESHICUNZAIYIGEXIAO bug DE,YOUXINGQUKEYIQUFAXIANYIXIA。

  SHANGWENZHUYAOSHIBAZAIBIANXIEHTMLGAOLIANGGUANJIANZIDESHIXIANDAIMAGUOCHENGZHONGXUYAOYONGDAODEXIANGGUANZILIAOJIDAJIAFENXIANGYIXIA,XIWANGKEYIBANGDAOPENGDAOSHANGSHUWENTIDEPENGYOU,RUGUODAJIAZHIDUIJIEGUOYOUXINGQUDEHUAYESHIKEYIZHIJIETIAODAOJIEWEIKANJIEGUODE。

延伸阅读:

Tag标签:   
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规