js addDqmForPP给标签内属性值加上双引号的函数
网络编程 2021-07-04 19:20www.168986.cn编程入门
这篇文章主要介绍了js addDqmForPP给标签内属性值加上双引号的函数,需要的朋友可以参考下
实现代码一:
给标签内属性值加上双引号
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}); };
完整测试代码
<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公司推出“汪力和李邦”网络广告 href=http://.genewscenter./{$content}\Detail.asp?ReleaseID=4886&NewsAreaID=2&changeCurrentLocale=5 _eventID="4">GE公司推出“汪力和李邦”网络广告</A></P></LI> <LI class=feed_item><SPAN class=note>26/11/2008</SPAN> <P><A title=GE石油天然气集团在中国创造新的快速安装记录 href="http://.genewscenter./content/Detail.asp?ReleaseID=4879&NewsAreaID=2&changeCurrentLocale=5" _eventID="5">GE石油天然气集团在中国创造新的快速安装记录</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>
实现代码二:
给标签内属性值加上双引号标记变小写
核心代码
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公司推出“汪力和李邦”网络广告 href="http://.genewscenter./content/Detail.asp?ReleaseID=4886&NewsAreaID=2&changeCurrentLocale=5" _eventID="4">GE公司推出“汪力和李邦”网络广告</A></P></LI> <LI class=feed_item><SPAN class=note>26/11/2008</SPAN> <P><A title=GE石油天然气集团在中国创造新的快速安装记录 href="http://.genewscenter./content/Detail.asp?ReleaseID=4879&NewsAreaID=2&changeCurrentLocale=5" _eventID="5">GE石油天然气集团在中国创造新的快速安装记录</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])" />
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程