(正则表达式应用) 替换自闭合标签(self-closing tag)的method
var str = "<sup><div class=\"he's\"/></sup><span id=\"cs\"/>";
function removeCloseTag(str) {
var regCloseTag = /<[^>]+\/>/,
regTagName = /[^<][^\s]+/,
tmp,
tagName;
while((tmp = str.match(regCloseTag)) && tmp.length > 0){
tagName = tmp[0].match(regTagName);
str = str.replace(/\/>/, '></'+tagName+'>');
}
return str;
}
var res = removeCloseTag(str); //<sup><div class="he's"></div></sup><span id="cs"></span>
Wisdom dawns when names and forms vanish.