欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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&amp;NewsAreaID=2&amp;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)文章

最新評(píng)論