javascript去掉a標(biāo)簽的方法:首先找到相應(yīng)的js代碼部分;然后通過(guò)“str.replace(/(<>)|(<>)/g, '');”方法去掉a標(biāo)簽即可。
本文操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
javascript怎么去掉a標(biāo)簽?
具體問(wèn)題:
js 去a標(biāo)簽留內(nèi)容
怎么用正則去除a標(biāo)簽,只留下內(nèi)容 http://git.oschina.net
將a標(biāo)簽部分替換為空的方式,不是直接取a標(biāo)簽的內(nèi)容,因?yàn)橛泻芏噙@樣的代碼,而且還有其它代碼要留在原地
<a href="http://git.oschina.net/" style="box-sizing: border-box; color: rgb(51, 51, 51); text-decoration: none; transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1); -webkit-transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1); max-width: 100%; transparent;"><span data-wiz-span="data-wiz-span" style="box-sizing: border-box; max-width: 100%; font-size: 14pt;">http://git.oschina.net</span></a>
實(shí)現(xiàn)方法:
(</?a.*?>)|(</?span.*?>)
也就是:
str.replace(/(</?a.*?>)|(</?span.*?>)/g, '');
運(yùn)行結(jié)果
【推薦學(xué)習(xí):javascript高級(jí)教程】