js addDqmForPP給標(biāo)簽內(nèi)屬性值加上雙引號(hào)的函數(shù)
更新時(shí)間:2016年12月24日 00:15:15 作者:dh20156
這篇文章主要介紹了js addDqmForPP給標(biāo)簽內(nèi)屬性值加上雙引號(hào)的函數(shù),需要的朋友可以參考下
實(shí)現(xiàn)代碼一:
給標(biāo)簽內(nèi)屬性值加上雙引號(hào)
var addDqmForPP = function(shtml){ return shtml.replace(/( [^\=]*\=)(\s?[^\"\s\>]*)/ig,function(a,b,c,d,e){return (c)?(new RegExp("<[^>]*"+c.replace(/(\^|\(|\)|\[|\]|\{|\}|\?|\-|\\|\/|\||\$)/g,'\\$1')+"[^>]*>","i").test(e))?b+'"'+c+'"':b+c:b}); };
完整測(cè)試代碼
<textarea id="t" style="height:200px; width:300px;"> <UL class=list> <LI class=feed_item><SPAN class=note>01/12/2008</SPAN> <P><A title=GE公司推出“汪力和李邦”網(wǎng)絡(luò)廣告 href=http://www.genewscenter.com/{$content}\Detail.asp?ReleaseID=4886&NewsAreaID=2&changeCurrentLocale=5 _eventID="4">GE公司推出“汪力和李邦”網(wǎng)絡(luò)廣告</A></P></LI> <LI class=feed_item><SPAN class=note>26/11/2008</SPAN> <P><A title=GE石油天然氣集團(tuán)在中國(guó)創(chuàng)造新的快速安裝記錄 _eventID="5">GE石油天然氣集團(tuán)在中國(guó)創(chuàng)造新的快速安裝記錄</A></P></LI></UL> </textarea> <script type="text/javascript"> var sa = '<a href=index.html>hello </a><input onlick=a(); typle="submit"/><input onlick=a(); value=ok typle="submit"/><span>a=8+4</span>'; var sb = document.getElementById('t').value; var addDqmForPP = function(shtml){ return shtml.replace(/( [^\=]*\=)(\s?[^\"\s\>]*)/ig,function(a,b,c,d,e){return (c)?(new RegExp("<[^>]*"+c.replace(/(\^|\(|\)|\[|\]|\{|\}|\?|\-|\\|\/|\||\$)/g,'\\$1')+"[^>]*>","i").test(e))?b+'"'+c+'"':b+c:b}); }; alert(addDqmForPP(sa)); alert(addDqmForPP(sb)); </script>
實(shí)現(xiàn)代碼二:
給標(biāo)簽內(nèi)屬性值加上雙引號(hào)標(biāo)記變小寫(xiě)
核心代碼
var partialXHTML = function (value) { return value.replace(/<(\/?[a-zA-Z]+\s*)((?:"[^"]*"|'[^']*'|(?!'|"|\/?>).)*)(\/?>)/g, function (l, $1, $2, $3) { return '<' + $1.toLowerCase() + $2.replace(/([^=]+)=(?:(")[^"]*"|(')[^']*'|((?:(?!\s|'|"|\/?>).)*))/g, function (l, $1, $2, $3, $4) { return ($2||$3) ? l : $1 + '="' + $4 + '"'; }) + $3; }); };
完整代碼
<textarea style="height:200px; width:300px;"> <UL class=list> <LI class=feed_item><SPAN class=note>01/12/2008</SPAN> <P><A title=GE公司推出“汪力和李邦”網(wǎng)絡(luò)廣告 _eventID="4">GE公司推出“汪力和李邦”網(wǎng)絡(luò)廣告</A></P></LI> <LI class=feed_item><SPAN class=note>26/11/2008</SPAN> <P><A title=GE石油天然氣集團(tuán)在中國(guó)創(chuàng)造新的快速安裝記錄 _eventID="5">GE石油天然氣集團(tuán)在中國(guó)創(chuàng)造新的快速安裝記錄</A></P></LI></UL> </textarea> <script type="text/javascript"> var partialXHTML = function (value) { return value.replace(/<(\/?[a-zA-Z]+\s*)((?:"[^"]*"|'[^']*'|(?!'|"|\/?>).)*)(\/?>)/g, function (l, $1, $2, $3) { return '<' + $1.toLowerCase() + $2.replace(/([^=]+)=(?:(")[^"]*"|(')[^']*'|((?:(?!\s|'|"|\/?>).)*))/g, function (l, $1, $2, $3, $4) { return ($2||$3) ? l : $1 + '="' + $4 + '"'; }) + $3; }); }; var parse = function (t) { t.value = partialXHTML(t.value); }; </script> <input type="button" value="修正" onclick="parse(document.getElementsByTagName('textarea')[0])" />
相關(guān)文章
網(wǎng)頁(yè)加載時(shí)頁(yè)面顯示進(jìn)度條加載完成之后顯示網(wǎng)頁(yè)內(nèi)容
網(wǎng)頁(yè)加載時(shí)頁(yè)面顯示進(jìn)度條(加載完成時(shí)顯示網(wǎng)頁(yè)內(nèi)容),這種效果在瀏覽網(wǎng)頁(yè)很常見(jiàn),本文也介紹一種實(shí)現(xiàn)方法,需要了解的朋友可以參考下2012-12-12小程序登錄/注冊(cè)頁(yè)面設(shè)計(jì)的實(shí)現(xiàn)代碼
這篇文章主要介紹了小程序登錄/注冊(cè)頁(yè)面設(shè)計(jì)的實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05javascript 閉包函數(shù)做顯隱內(nèi)容
用閉包函數(shù)做顯隱內(nèi)容,主要優(yōu)勢(shì)就是可以增加顯示與隱藏效率。2009-03-03利用OpenAI?ChatGPT進(jìn)行編碼嘗試體驗(yàn)
這幾天chatgpt可是非常火的,下面這篇文章主要給大家介紹了關(guān)于利用OpenAI?ChatGPT進(jìn)行編碼嘗試體驗(yàn)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12javascript實(shí)現(xiàn)十秒鐘后注冊(cè)按鈕可點(diǎn)擊的方法
這篇文章主要介紹了javascript實(shí)現(xiàn)十秒鐘后注冊(cè)按鈕可點(diǎn)擊的方法,涉及javascript時(shí)間及樣式操作的相關(guān)技巧,需要的朋友可以參考下2015-05-05