javascript去掉a標簽的方法:首先找到相應的js代碼部分;然后通過“str.replace(/(<>)|(<>)/g, '');”方法去掉a標簽即可。
本文操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
javascript怎么去掉a標簽?
具體問題:
js 去a標簽留內(nèi)容
怎么用正則去除a標簽,只留下內(nèi)容 http://git.oschina.net
將a標簽部分替換為空的方式,不是直接取a標簽的內(nèi)容,因為有很多這樣的代碼,而且還有其它代碼要留在原地
<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>
實現(xiàn)方法:
(</?a.*?>)|(</?span.*?>)
也就是:
str.replace(/(</?a.*?>)|(</?span.*?>)/g, '');
運行結(jié)果
【推薦學習:javascript高級教程】